Fixes analog read for pins A6 and A7#338
Conversation
|
Board and firmware folder for this pull request: |
|
Board and firmware folder for this pull request: |
| // therefore reading from A6 and A7 does not work | ||
| // via "digital" pins. See also pins_arduino.h | ||
| if (_pin == 4) | ||
| _pin = A6; |
There was a problem hiding this comment.
Alternatively we could have mapped the label A6 in the boards.json file, no?
That would leave this special treatment out here. My first thought was, that special handling for certain variants is not so great. i know we have done it for Pico, but that's an entirely different platform.
DocMoebiuz
left a comment
There was a problem hiding this comment.
Can we chat about this change and see if we want to keep it here?
|
Board and firmware folder for this pull request: |
|
Summary from our chat on Discord: Analog A6 is on pin 4. To use this pin 4 as analog in, the Arduino framework expects analogRead(A6). A6 is defined as 24 in the .h file. The analogRead() function subtracts 18 for pin numbers > 18. So I can also specify the value 6 as the pin number. But that is not pin 4 that I want to connect the potentiometer to. Ax (x-18 if x>17) is equivalent to digital pin x, except for A6 and A7. Therefore you have to check if it is one of these two pins and then map it. This special feature, that the digital pin number cannot be used for analogRead(), only exists with these two pins on the ProMicro. I see no chance just to do it in the board.json file. See also from arduino_pins.h: Are there anymore informations requuired to merge this Pullrequest? |
Description of changes
ProMicro has some special pin mapping within pins_arduino.h through which analog pins
A6andA7can not be adressed via there digital pin numbers. But Mobiflight does only use the digital pin numbers also for pins with analog readin function.With this change it is checked if the digitla pin number is one of the two pin numbers and in this case a reampping is done so that the pin number fits to the required one.
Fixes #337