aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_analog.c
diff options
context:
space:
mode:
authorZach Eveland <zeveland@blacklabel-development.com>2011-09-13 23:52:26 -0400
committerZach Eveland <zeveland@blacklabel-development.com>2011-09-13 23:52:26 -0400
commitd0b0f3e45d5c4cf3a7fbcf5832c5e6cc764016e0 (patch)
treee1ad6e1c36d07612e0e4bb105aa55b120b71e54d /cores/arduino/wiring_analog.c
parent15c4c969298c303899bf80fbc962591d84163216 (diff)
fixed analog pin mapping for 32u4
Diffstat (limited to 'cores/arduino/wiring_analog.c')
-rw-r--r--cores/arduino/wiring_analog.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c
index d248f4c..62b91cf 100644
--- a/cores/arduino/wiring_analog.c
+++ b/cores/arduino/wiring_analog.c
@@ -46,8 +46,11 @@ int analogRead(uint8_t pin)
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif
-
-#if defined(ADCSRB) && defined(MUX5)
+
+#if defined(__AVR_ATmega32U4__)
+ pin = analogPinToChannel(pin);
+ ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
+#elif defined(ADCSRB) && defined(MUX5)
// the MUX5 bit of ADCSRB selects whether we're reading from channels
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);