Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes analog read for pins A6 and A7 #338

Merged
merged 4 commits into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/MF_Analog/MFAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity)
_sensitivity = sensitivity;
_pin = pin;
_name = name;
#if defined(ARDUINO_AVR_PROMICRO16)
// ProMicro has a special pin assignment for analog pins
// therefore reading from A6 and A7 does not work
// via "digital" pins. See also pins_arduino.h
if (_pin == 4)
_pin = A6;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

else if (_pin == 6)
_pin = A7;
#endif
pinMode(_pin, INPUT_PULLUP); // set pin to input. Could use OUTPUT for analog, but shows the intention :-)
// Fill averaging buffers with initial reading
for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) {
Expand Down
Loading