Skip to content

Commit 04475f4

Browse files
committed
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.
1 parent 336e890 commit 04475f4

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

cores/arduino/WProgram.h

+29
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ long random(long);
2727
long random(long, long);
2828
void randomSeed(unsigned int);
2929
long map(long, long, long, long, long);
30+
31+
#if defined(__AVR_ATmega1280__)
32+
const static uint8_t A0 = 54;
33+
const static uint8_t A1 = 55;
34+
const static uint8_t A2 = 56;
35+
const static uint8_t A3 = 57;
36+
const static uint8_t A4 = 58;
37+
const static uint8_t A5 = 59;
38+
const static uint8_t A6 = 60;
39+
const static uint8_t A7 = 61;
40+
const static uint8_t A8 = 62;
41+
const static uint8_t A9 = 63;
42+
const static uint8_t A10 = 64;
43+
const static uint8_t A11 = 65;
44+
const static uint8_t A12 = 66;
45+
const static uint8_t A13 = 67;
46+
const static uint8_t A14 = 68;
47+
const static uint8_t A15 = 69;
48+
#else
49+
const static uint8_t A0 = 14;
50+
const static uint8_t A1 = 15;
51+
const static uint8_t A2 = 16;
52+
const static uint8_t A3 = 17;
53+
const static uint8_t A4 = 18;
54+
const static uint8_t A5 = 19;
55+
const static uint8_t A6 = 20;
56+
const static uint8_t A7 = 21;
57+
#endif
58+
3059
#endif
3160

3261
#endif

cores/arduino/pins_arduino.c

-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@
7777
#define PK 11
7878
#define PL 12
7979

80-
#define REPEAT8(x) x, x, x, x, x, x, x, x
81-
#define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7)
82-
#define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0)
83-
8480

8581
#if defined(__AVR_ATmega1280__)
8682
const uint16_t PROGMEM port_to_mode_PGM[] = {

cores/arduino/wiring.h

-6
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ int analogRead(uint8_t);
106106
void analogReference(uint8_t mode);
107107
void analogWrite(uint8_t, int);
108108

109-
void beginSerial(long);
110-
void serialWrite(unsigned char);
111-
int serialAvailable(void);
112-
int serialRead(void);
113-
void serialFlush(void);
114-
115109
unsigned long millis(void);
116110
unsigned long micros(void);
117111
void delay(unsigned long);

cores/arduino/wiring_analog.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ int analogRead(uint8_t pin)
3939
{
4040
uint8_t low, high;
4141

42-
// set the analog reference (high two bits of ADMUX) and select the
43-
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
44-
// to 0 (the default).
45-
ADMUX = (analog_reference << 6) | (pin & 0x07);
46-
4742
#if defined(__AVR_ATmega1280__)
43+
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
44+
4845
// the MUX5 bit of ADCSRB selects whether we're reading from channels
4946
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
5047
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
48+
#else
49+
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
5150
#endif
51+
52+
// set the analog reference (high two bits of ADMUX) and select the
53+
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
54+
// to 0 (the default).
55+
ADMUX = (analog_reference << 6) | (pin & 0x07);
5256

5357
// without a delay, we seem to read from the wrong channel
5458
//delay(1);

0 commit comments

Comments
 (0)