diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-05-16 04:05:40 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-05-16 04:05:40 +0000 |
commit | 04475f4bfed43d3e956ffeb28e8aa4b552f922f7 (patch) | |
tree | d3a36592fb7f90b88666c269cfe4cc12f66f0cf9 /cores/arduino/wiring_analog.c | |
parent | 336e8908231319e4566ce1d2a92616455511d2de (diff) |
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.
Diffstat (limited to 'cores/arduino/wiring_analog.c')
-rwxr-xr-x | cores/arduino/wiring_analog.c | 14 |
1 files changed, 9 insertions, 5 deletions
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); |