aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-05-16 04:05:40 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-05-16 04:05:40 +0000
commit04475f4bfed43d3e956ffeb28e8aa4b552f922f7 (patch)
treed3a36592fb7f90b88666c269cfe4cc12f66f0cf9 /cores
parent336e8908231319e4566ce1d2a92616455511d2de (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')
-rwxr-xr-xcores/arduino/WProgram.h29
-rwxr-xr-xcores/arduino/pins_arduino.c4
-rwxr-xr-xcores/arduino/wiring.h6
-rwxr-xr-xcores/arduino/wiring_analog.c14
4 files changed, 38 insertions, 15 deletions
diff --git a/cores/arduino/WProgram.h b/cores/arduino/WProgram.h
index f5d3e29..39dc611 100755
--- a/cores/arduino/WProgram.h
+++ b/cores/arduino/WProgram.h
@@ -27,6 +27,35 @@ long random(long);
long random(long, long);
void randomSeed(unsigned int);
long map(long, long, long, long, long);
+
+#if defined(__AVR_ATmega1280__)
+const static uint8_t A0 = 54;
+const static uint8_t A1 = 55;
+const static uint8_t A2 = 56;
+const static uint8_t A3 = 57;
+const static uint8_t A4 = 58;
+const static uint8_t A5 = 59;
+const static uint8_t A6 = 60;
+const static uint8_t A7 = 61;
+const static uint8_t A8 = 62;
+const static uint8_t A9 = 63;
+const static uint8_t A10 = 64;
+const static uint8_t A11 = 65;
+const static uint8_t A12 = 66;
+const static uint8_t A13 = 67;
+const static uint8_t A14 = 68;
+const static uint8_t A15 = 69;
+#else
+const static uint8_t A0 = 14;
+const static uint8_t A1 = 15;
+const static uint8_t A2 = 16;
+const static uint8_t A3 = 17;
+const static uint8_t A4 = 18;
+const static uint8_t A5 = 19;
+const static uint8_t A6 = 20;
+const static uint8_t A7 = 21;
+#endif
+
#endif
#endif \ No newline at end of file
diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c
index 1c1c088..b662058 100755
--- a/cores/arduino/pins_arduino.c
+++ b/cores/arduino/pins_arduino.c
@@ -77,10 +77,6 @@
#define PK 11
#define PL 12
-#define REPEAT8(x) x, x, x, x, x, x, x, x
-#define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7)
-#define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0)
-
#if defined(__AVR_ATmega1280__)
const uint16_t PROGMEM port_to_mode_PGM[] = {
diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h
index e6dcde1..edc9704 100755
--- a/cores/arduino/wiring.h
+++ b/cores/arduino/wiring.h
@@ -106,12 +106,6 @@ int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
-void beginSerial(long);
-void serialWrite(unsigned char);
-int serialAvailable(void);
-int serialRead(void);
-void serialFlush(void);
-
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
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);