From 04475f4bfed43d3e956ffeb28e8aa4b552f922f7 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 16 May 2010 04:05:40 +0000 Subject: Adding A0=14, A1=15, etc. aliases for analog input pins and modifying analogRead() to accept them (in addition to 0, 1, 2, etc.). Removing some unused code elsewhere. --- cores/arduino/wiring_analog.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'cores/arduino/wiring_analog.c') diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 529ad52..63be477 100755 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -39,16 +39,20 @@ int analogRead(uint8_t pin) { uint8_t low, high; - // set the analog reference (high two bits of ADMUX) and select the - // channel (low 4 bits). this also sets ADLAR (left-adjust result) - // to 0 (the default). - ADMUX = (analog_reference << 6) | (pin & 0x07); - #if defined(__AVR_ATmega1280__) + if (pin >= 54) pin -= 54; // allow for channel or pin numbers + // 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); +#else + if (pin >= 14) pin -= 14; // allow for channel or pin numbers #endif + + // set the analog reference (high two bits of ADMUX) and select the + // channel (low 4 bits). this also sets ADLAR (left-adjust result) + // to 0 (the default). + ADMUX = (analog_reference << 6) | (pin & 0x07); // without a delay, we seem to read from the wrong channel //delay(1); -- cgit v1.2.3-18-g5258