set address by GPIOs 11, 12, 13
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
#define PIN_HEADING_WHITE PD3
|
#define PIN_HEADING_WHITE 3
|
||||||
#define PIN_HEADING_RED PD6
|
#define PIN_HEADING_RED 5
|
||||||
|
|
||||||
#define PIN_ALTITUDE_WHITE PD2
|
#define PIN_ALTITUDE_WHITE 2
|
||||||
#define PIN_ALTITUDE_RED PD5
|
#define PIN_ALTITUDE_RED 4
|
||||||
|
|
||||||
#define VALUE_BUFFER 30
|
#define VALUE_BUFFER 30
|
||||||
|
|
||||||
@ -16,6 +16,9 @@
|
|||||||
#define HEADING_HIGH_BIT 2
|
#define HEADING_HIGH_BIT 2
|
||||||
#define ALTITUDE_TRIGGER_BIT 4
|
#define ALTITUDE_TRIGGER_BIT 4
|
||||||
#define ALTITUDE_HIGH_BIT 8
|
#define ALTITUDE_HIGH_BIT 8
|
||||||
|
#define PIN_ADDRESS_1 11
|
||||||
|
#define PIN_ADDRESS_2 12
|
||||||
|
#define PIN_ADDRESS_3 13
|
||||||
|
|
||||||
int lastClk = HIGH;
|
int lastClk = HIGH;
|
||||||
|
|
||||||
@ -92,18 +95,30 @@ void i2cRequest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t address = 0;
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// setup rotator GPIOs
|
||||||
pinMode(PIN_HEADING_WHITE, INPUT_PULLUP);
|
pinMode(PIN_HEADING_WHITE, INPUT_PULLUP);
|
||||||
pinMode(PIN_HEADING_RED, INPUT_PULLUP);
|
pinMode(PIN_HEADING_RED, INPUT_PULLUP);
|
||||||
pinMode(PIN_ALTITUDE_WHITE, INPUT_PULLUP);
|
pinMode(PIN_ALTITUDE_WHITE, INPUT_PULLUP);
|
||||||
pinMode(PIN_ALTITUDE_RED, INPUT_PULLUP);
|
pinMode(PIN_ALTITUDE_RED, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// setup address selector GPIOs
|
||||||
|
pinMode(PIN_ADDRESS_1, INPUT_PULLUP);
|
||||||
|
pinMode(PIN_ADDRESS_2, INPUT_PULLUP);
|
||||||
|
pinMode(PIN_ADDRESS_3, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// calculate address by LOW GPIOs
|
||||||
|
address = digitalRead(PIN_ADDRESS_1) == LOW;
|
||||||
|
address |= (digitalRead(PIN_ADDRESS_2) == LOW) << 1;
|
||||||
|
address |= (digitalRead(PIN_ADDRESS_3) == LOW) << 2;
|
||||||
|
|
||||||
attachInterrupt(digitalPinToInterrupt(PIN_ALTITUDE_WHITE), altitudeFalling, FALLING);
|
attachInterrupt(digitalPinToInterrupt(PIN_ALTITUDE_WHITE), altitudeFalling, FALLING);
|
||||||
attachInterrupt(digitalPinToInterrupt(PIN_HEADING_WHITE), headingFalling, FALLING);
|
attachInterrupt(digitalPinToInterrupt(PIN_HEADING_WHITE), headingFalling, FALLING);
|
||||||
|
|
||||||
Wire.begin(0x01);
|
Wire.begin(address);
|
||||||
Wire.onRequest(i2cRequest);
|
Wire.onRequest(i2cRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user