generalized rotator ino

This commit is contained in:
2025-05-11 19:31:07 +02:00
parent afffd831f4
commit 5c1a32cda2

View File

@ -1,10 +1,10 @@
#include <Wire.h> #include <Wire.h>
#define PIN_HEADING_WHITE 3 #define PIN_ROTATOR1_WHITE 2
#define PIN_HEADING_RED 5 #define PIN_ROTATOR1_GREEN 4
#define PIN_ALTITUDE_WHITE 2 #define PIN_ROTATOR2_WHITE 3
#define PIN_ALTITUDE_RED 4 #define PIN_ROTATOR2_GREEN 5
#define VALUE_BUFFER 30 #define VALUE_BUFFER 30
@ -12,10 +12,10 @@
// needs global define // needs global define
#define DATA_STOP_BYTE 0x00 #define DATA_STOP_BYTE 0x00
#define HEADING_TRIGGER_BIT 1 #define ROTATOR1_TRIGGER_BIT 1
#define HEADING_HIGH_BIT 2 #define ROTATOR1_HIGH_BIT 2
#define ALTITUDE_TRIGGER_BIT 4 #define ROTATOR2_TRIGGER_BIT 4
#define ALTITUDE_HIGH_BIT 8 #define ROTATOR2_HIGH_BIT 8
#define PIN_ADDRESS_1 11 #define PIN_ADDRESS_1 11
#define PIN_ADDRESS_2 12 #define PIN_ADDRESS_2 12
#define PIN_ADDRESS_3 13 #define PIN_ADDRESS_3 13
@ -49,12 +49,12 @@ void falling(uint8_t pin, byte triggerBit, byte highBit) {
} }
} }
void headingFalling() { void rotator1Falling() {
falling(PIN_HEADING_RED, HEADING_TRIGGER_BIT, HEADING_HIGH_BIT); falling(PIN_ROTATOR1_GREEN, ROTATOR1_TRIGGER_BIT, ROTATOR1_HIGH_BIT);
} }
void altitudeFalling() { void rotator2Falling() {
falling(PIN_ALTITUDE_RED, ALTITUDE_TRIGGER_BIT, ALTITUDE_HIGH_BIT); falling(PIN_ROTATOR2_GREEN, ROTATOR2_TRIGGER_BIT, ROTATOR2_HIGH_BIT);
} }
int eventCount = 0; int eventCount = 0;
@ -100,11 +100,11 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
// setup rotator GPIOs // setup rotator GPIOs
pinMode(PIN_HEADING_WHITE, INPUT_PULLUP); pinMode(PIN_ROTATOR1_WHITE, INPUT_PULLUP);
pinMode(PIN_HEADING_RED, INPUT_PULLUP); pinMode(PIN_ROTATOR1_GREEN, INPUT_PULLUP);
pinMode(PIN_ALTITUDE_WHITE, INPUT_PULLUP); pinMode(PIN_ROTATOR2_WHITE, INPUT_PULLUP);
pinMode(PIN_ALTITUDE_RED, INPUT_PULLUP); pinMode(PIN_ROTATOR2_GREEN, INPUT_PULLUP);
// setup address selector GPIOs // setup address selector GPIOs
pinMode(PIN_ADDRESS_1, INPUT_PULLUP); pinMode(PIN_ADDRESS_1, INPUT_PULLUP);
pinMode(PIN_ADDRESS_2, INPUT_PULLUP); pinMode(PIN_ADDRESS_2, INPUT_PULLUP);
@ -115,8 +115,8 @@ void setup() {
address |= (digitalRead(PIN_ADDRESS_2) == LOW) << 1; address |= (digitalRead(PIN_ADDRESS_2) == LOW) << 1;
address |= (digitalRead(PIN_ADDRESS_3) == LOW) << 2; address |= (digitalRead(PIN_ADDRESS_3) == LOW) << 2;
attachInterrupt(digitalPinToInterrupt(PIN_ALTITUDE_WHITE), altitudeFalling, FALLING); attachInterrupt(digitalPinToInterrupt(PIN_ROTATOR1_WHITE), rotator1Falling, FALLING);
attachInterrupt(digitalPinToInterrupt(PIN_HEADING_WHITE), headingFalling, FALLING); attachInterrupt(digitalPinToInterrupt(PIN_ROTATOR2_WHITE), rotator2Falling, FALLING);
Wire.begin(address); Wire.begin(address);
Wire.onRequest(i2cRequest); Wire.onRequest(i2cRequest);