I'm new to Arduino, and my Nanos haven't arrived yet. But I've worked with Energia, which is a port of the Arduino IDE for TI's MSP430 MCUs, and I'm confused about the definitions of pin names in Arduino. In Energia, pin numbers for digital I/O refer to the actual processor pin number, but in Arduino that appears not to be the case, and apparently it's different for digital and analog pins. Looking through the examples, here's what I find:
Button
Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 2.
The circuit:
-
LED attached from pin 13 to ground
-
pushbutton attached to pin 2 from +5V
-
10K resistor attached to pin 2 from ground
-
Note: on most Arduinos there is already an LED on the board
attached to pin 13.
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
The LED pin is referred to as pin 13, not as pin D13. It is not actually pin 13 of the 328 (it's pin 17), or pin 13 of the 30-pin Nano board (it's pin 16), but it is the pin labeled as D13. But searching through all of the Examples folder, I can't find a single instancce of anyone defining a pin name as Dn. It's always just the number - 13 in this case. On the other hand, analog pins are always referred to as An.
Is my understanding correct about this? Would it be considered bad programming practice, and confusing to others, if I assigned the LEDpin as D13? Would it even work (i.e. -- will the compiler know "D13")?
Also, I found a discussion here about whether these pin assignment constants should be bytes or ints, but I didn't see where a conclusion was reached. Should pins always be ints? Would using bytes save any room, or just make it worse? I assume the An (and Dn if they exist) values are ints, but does that preclude using byte definitions?
Thanks for any clarification.