Skip to content

Commit ffe5a3f

Browse files
committed
Avoid to have first analog pin value (A0) lesser than NUM_ANALOG_INPUTS
To be able to use analogRead(A0) and analogRead(0), A0 pin value must be greater than or equal to NUM_ANALOG_INPUTS. Ex: If NUM_ANALOG_INPUTS was 6 (A0 to A5) and A0 was defined to 3 (D3), analogRead(A0) would read A3 instead of A0. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 5e4ac46 commit ffe5a3f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Diff for: cores/arduino/pins_arduino.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ enum {
5050
// Arduino analog pins
5151
// Analog pins must be contiguous to be able to loop on each value
5252
#define MAX_ANALOG_INPUTS 20
53-
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS, "Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS" );
53+
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS,
54+
"Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS" );
55+
_Static_assert(NUM_ANALOG_FIRST >= NUM_ANALOG_INPUTS,
56+
"First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS" );
5457

5558
// Defined for backward compatibility with Firmata which unfortunately use it
5659
#define AEND (NUM_ANALOG_FIRST+NUM_ANALOG_INPUTS)

Diff for: variants/board_template/variant.h

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum {
7575
// !!!
7676
#define NUM_ANALOG_INPUTS 0
7777
// Define digital pin number of the first analog input (i.e. which digital pin is A0)
78+
// First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS
7879
#define NUM_ANALOG_FIRST 0
7980

8081
// Below ADC, DAC and PWM definitions already done in the core

0 commit comments

Comments
 (0)