Closed ricklon closed 7 years ago
I've confirmed the issue in the following code. Additionally, I've tested functions that could fix this. I'll update and submit a pull request.
#define PROP_IS_PIN_ANALOG(p) ((p) == 0 || ((p) >= 3 && (p) <= 13) || (p) == 20) #define PROP_PIN_TO_ANALOG(p) ((p) == 0 ? 0 : ((((p) >= 1 && (p) <= 11)) ? ((p) + 2) : (p)) ) #include <Servo.h> #include <Wire.h> #include <Firmata.h> void setup() { pinMode(PIN_BTN1, INPUT); Serial.begin(9600); } void loop() { static uint8_t p1 = digitalRead(PIN_BTN1); if (digitalRead(PIN_BTN1) != p1) { p1 = digitalRead(PIN_BTN1); if (p1 == HIGH) { Serial.println("Firmata: Current"); for (int ii = 0; ii < 22; ii += 1) { Serial.printf("A%d, toPin: %d, isPinAnalog: %d\n", ii, PIN_TO_ANALOG(ii), IS_PIN_ANALOG(PIN_TO_ANALOG(ii))); } Serial.println("Firmata: Proposed"); for (int ii = 0; ii < 22; ii += 1) { Serial.printf("A%d, toPin: %d, isPinAnalog: %d\n", ii, PROP_PIN_TO_ANALOG(ii), PROP_IS_PIN_ANALOG(PROP_PIN_TO_ANALOG(ii))); } } } }
Resulting Data: Firmata: Current A0, toPin: 0, isPinAnalog: 1 A1, toPin: 1, isPinAnalog: 0 A2, toPin: 2, isPinAnalog: 0 A3, toPin: 3, isPinAnalog: 1 A4, toPin: 4, isPinAnalog: 1 A5, toPin: 5, isPinAnalog: 1 A6, toPin: 6, isPinAnalog: 1 A7, toPin: 7, isPinAnalog: 1 A8, toPin: 8, isPinAnalog: 1 A9, toPin: 9, isPinAnalog: 1 A10, toPin: 10, isPinAnalog: 1 A11, toPin: 11, isPinAnalog: 1 A12, toPin: 12, isPinAnalog: 1 A13, toPin: 13, isPinAnalog: 1 A14, toPin: 14, isPinAnalog: 0 A15, toPin: 15, isPinAnalog: 0 A16, toPin: 16, isPinAnalog: 0 A17, toPin: 17, isPinAnalog: 0 A18, toPin: 18, isPinAnalog: 0 A19, toPin: 19, isPinAnalog: 0 A20, toPin: 20, isPinAnalog: 0 Firmata: Proposed A0, toPin: 0, isPinAnalog: 1 A1, toPin: 3, isPinAnalog: 1 A2, toPin: 4, isPinAnalog: 1 A3, toPin: 5, isPinAnalog: 1 A4, toPin: 6, isPinAnalog: 1 A5, toPin: 7, isPinAnalog: 1 A6, toPin: 8, isPinAnalog: 1 A7, toPin: 9, isPinAnalog: 1 A8, toPin: 10, isPinAnalog: 1 A9, toPin: 11, isPinAnalog: 1 A10, toPin: 12, isPinAnalog: 1 A11, toPin: 13, isPinAnalog: 1 A12, toPin: 12, isPinAnalog: 1 A13, toPin: 13, isPinAnalog: 1 A14, toPin: 14, isPinAnalog: 0 A15, toPin: 15, isPinAnalog: 0 A16, toPin: 16, isPinAnalog: 0 A17, toPin: 17, isPinAnalog: 0 A18, toPin: 18, isPinAnalog: 0 A19, toPin: 19, isPinAnalog: 0 A20, toPin: 20, isPinAnalog: 1
Arg. Wrong repos. Closing.
I've confirmed the issue in the following code. Additionally, I've tested functions that could fix this. I'll update and submit a pull request.
Resulting Data: Firmata: Current A0, toPin: 0, isPinAnalog: 1 A1, toPin: 1, isPinAnalog: 0 A2, toPin: 2, isPinAnalog: 0 A3, toPin: 3, isPinAnalog: 1 A4, toPin: 4, isPinAnalog: 1 A5, toPin: 5, isPinAnalog: 1 A6, toPin: 6, isPinAnalog: 1 A7, toPin: 7, isPinAnalog: 1 A8, toPin: 8, isPinAnalog: 1 A9, toPin: 9, isPinAnalog: 1 A10, toPin: 10, isPinAnalog: 1 A11, toPin: 11, isPinAnalog: 1 A12, toPin: 12, isPinAnalog: 1 A13, toPin: 13, isPinAnalog: 1 A14, toPin: 14, isPinAnalog: 0 A15, toPin: 15, isPinAnalog: 0 A16, toPin: 16, isPinAnalog: 0 A17, toPin: 17, isPinAnalog: 0 A18, toPin: 18, isPinAnalog: 0 A19, toPin: 19, isPinAnalog: 0 A20, toPin: 20, isPinAnalog: 0 Firmata: Proposed A0, toPin: 0, isPinAnalog: 1 A1, toPin: 3, isPinAnalog: 1 A2, toPin: 4, isPinAnalog: 1 A3, toPin: 5, isPinAnalog: 1 A4, toPin: 6, isPinAnalog: 1 A5, toPin: 7, isPinAnalog: 1 A6, toPin: 8, isPinAnalog: 1 A7, toPin: 9, isPinAnalog: 1 A8, toPin: 10, isPinAnalog: 1 A9, toPin: 11, isPinAnalog: 1 A10, toPin: 12, isPinAnalog: 1 A11, toPin: 13, isPinAnalog: 1 A12, toPin: 12, isPinAnalog: 1 A13, toPin: 13, isPinAnalog: 1 A14, toPin: 14, isPinAnalog: 0 A15, toPin: 15, isPinAnalog: 0 A16, toPin: 16, isPinAnalog: 0 A17, toPin: 17, isPinAnalog: 0 A18, toPin: 18, isPinAnalog: 0 A19, toPin: 19, isPinAnalog: 0 A20, toPin: 20, isPinAnalog: 1