If I used D5 in my code I get an undefined message (Nano):
But if as an experiment I put A5 it compiles.
void setup() {
// put your setup code here, to run once:
pinMode (D5,INPUT_PULLUP) ;
}
void loop() {
// put your main code here, to run repeatedly:
digitalRead (D5)
}
What again have I missed? This is the new IDE if that makes a difference...
You can see it has definitions for A0 to A7, but no such definition for D5 etc.
Note1: I didn't use the Arduino IDE (1.8.?), I used a PlatformIO project that uses the Nano. I don't remember how to find the system header files in the IDE. With PlatformIO I can just right click on e.g. A1 and select "go to definition". I chose to do that now because it's easier for me.
That would work, but maybe this only seems clearer because you haven't done much work using the standard pin definitions yet.
What I find useful is to have a header file like this, for each project, particularly for projects containing multiple files:
Portpins.h
#ifndef PortPins_h
#define PortPins_h
// used by nano serial 0
// used by nano serial 1
#define PIN_Z80_D1 2
#define PIN_Z80_D0 3
#define PIN_Z80_D2 4
#define PIN_Z80_D3 5
#define PIN_Z80_D4 6
#define PIN_Z80_D5 7
#define PIN_165_SERIN 8
#define PIN_Z80_D6 9
// free 10
// free 11
#define PIN_Z80_RESET 12
#define PIN_165_SHCLK 13
#define PIN_165_SHLD A0
#define PIN_Z80_D7 A1
#define PIN_Z80_CLK A2
#define PIN_Z80_INT A3
#define PIN_Z80_NMI A4
// free A5
// free analog only A6
// free analog only A7
#endif
I.e. define what you are using the pins for. That makes the sketch code more readable.
For digging up a link to the source for posting, I usually search for "github arduino core" and then find the lines:
The rest of the file shows how it's all defined by an array of digital pin numbers, and how all the other definitions are defined.
You could, but since the underlying indexing for everything else is the "digital pin number as used by digitalRead(pin)" all that would be is prefixing the digital pin number with a "D". You could do something similar with a macro: