set address by GPIOs 11, 12, 13

This commit is contained in:
2025-05-11 19:19:32 +02:00
parent 5cea555e77
commit 6c1ad80e86

View File

@ -1,10 +1,10 @@
#include <Wire.h>
#define PIN_HEADING_WHITE PD3
#define PIN_HEADING_RED PD6
#define PIN_HEADING_WHITE 3
#define PIN_HEADING_RED 5
#define PIN_ALTITUDE_WHITE PD2
#define PIN_ALTITUDE_RED PD5
#define PIN_ALTITUDE_WHITE 2
#define PIN_ALTITUDE_RED 4
#define VALUE_BUFFER 30
@ -16,6 +16,9 @@
#define HEADING_HIGH_BIT 2
#define ALTITUDE_TRIGGER_BIT 4
#define ALTITUDE_HIGH_BIT 8
#define PIN_ADDRESS_1 11
#define PIN_ADDRESS_2 12
#define PIN_ADDRESS_3 13
int lastClk = HIGH;
@ -92,18 +95,30 @@ void i2cRequest() {
}
}
uint8_t address = 0;
void setup() {
Serial.begin(115200);
// setup rotator GPIOs
pinMode(PIN_HEADING_WHITE, INPUT_PULLUP);
pinMode(PIN_HEADING_RED, INPUT_PULLUP);
pinMode(PIN_ALTITUDE_WHITE, 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_HEADING_WHITE), headingFalling, FALLING);
Wire.begin(0x01);
Wire.begin(address);
Wire.onRequest(i2cRequest);
}