I'm using an Arduino nano . I prefer to use Pin Names (A0,A1,A2.... D4,D5,D6 ....etc,etc) instead of the corresponding Pin Numbers (19,20,21, etc, etc, etc).
Right now I use the #define statements to set this up. This works fine but I would like to just use an #include statement to get the same functionality. Is there a header file that I can use?
The Arduino core already carries out a translation internally, so that pin designations (which you call pin numbers, labeled on the Arduino board) are mapped to internal CPU port and port bit.
The mapping changes between different Arduino models, which is why you need a board definition file.
I can understand you preferring to use the A* names for analogue pins, especially when they are used as digital pins, as that distinguishes them from the purely digital pins with the same numbers, but why the aversion to just numbers for the digital only pins ? After all, they are printed on the board.
I assume that you realise that the pin numbers printed on the board are not the actual pin numbers of the AtMega328 chip
Better in my view to give each pin a name that relates to what you are using it for.
wildbill:
Better in my view to give each pin a name that relates to what you are using it for.
Agreed wholeheartedly but following the OPs logic would lead to declarations such as
const byte ledPin = D2;
when
const byte ledPin = 2;
would be a simple alternative
Here you go:
PinNames.h
#if NUM_DIGITAL_PINS > 0
const byte D0 = 0 ;
#endif
#if NUM_DIGITAL_PINS > 1
const byte D1 = 1 ;
#endif
#if NUM_DIGITAL_PINS > 2
const byte D2 = 2 ;
#endif
#if NUM_DIGITAL_PINS > 3
const byte D3 = 3 ;
#endif
#if NUM_DIGITAL_PINS > 4
const byte D4 = 4 ;
#endif
#if NUM_DIGITAL_PINS > 5
const byte D5 = 5 ;
#endif
#if NUM_DIGITAL_PINS > 6
const byte D6 = 6 ;
#endif
#if NUM_DIGITAL_PINS > 7
const byte D7 = 7 ;
#endif
#if NUM_DIGITAL_PINS > 8
const byte D8 = 8 ;
#endif
#if NUM_DIGITAL_PINS > 9
const byte D9 = 9 ;
#endif
#if NUM_DIGITAL_PINS > 10
const byte D10 = 10 ;
#endif
#if NUM_DIGITAL_PINS > 11
const byte D11 = 11 ;
#endif
#if NUM_DIGITAL_PINS > 12
const byte D12 = 12 ;
#endif
#if NUM_DIGITAL_PINS > 13
const byte D13 = 13 ;
#endif
#if NUM_DIGITAL_PINS > 14
const byte D14 = 14 ;
#endif
#if NUM_DIGITAL_PINS > 15
const byte D15 = 15 ;
#endif
#if NUM_DIGITAL_PINS > 16
const byte D16 = 16 ;
#endif
#if NUM_DIGITAL_PINS > 17
const byte D17 = 17 ;
#endif
#if NUM_DIGITAL_PINS > 18
const byte D18 = 18 ;
#endif
#if NUM_DIGITAL_PINS > 19
const byte D19 = 19 ;
#endif
#if NUM_DIGITAL_PINS > 20
const byte D20 = 20 ;
#endif
#if NUM_DIGITAL_PINS > 21
const byte D21 = 21 ;
#endif
#if NUM_DIGITAL_PINS > 22
const byte D22 = 22 ;
#endif
#if NUM_DIGITAL_PINS > 23
const byte D23 = 23 ;
#endif
#if NUM_DIGITAL_PINS > 24
const byte D24 = 24 ;
#endif
#if NUM_DIGITAL_PINS > 25
const byte D25 = 25 ;
#endif
#if NUM_DIGITAL_PINS > 26
const byte D26 = 26 ;
#endif
#if NUM_DIGITAL_PINS > 27
const byte D27 = 27 ;
#endif
#if NUM_DIGITAL_PINS > 28
const byte D28 = 28 ;
#endif
#if NUM_DIGITAL_PINS > 29
const byte D29 = 29 ;
#endif
#if NUM_DIGITAL_PINS > 30
const byte D30 = 30 ;
#endif
#if NUM_DIGITAL_PINS > 31
const byte D31 = 31 ;
#endif
#if NUM_DIGITAL_PINS > 32
const byte D32 = 32 ;
#endif
#if NUM_DIGITAL_PINS > 33
const byte D33 = 33 ;
#endif
#if NUM_DIGITAL_PINS > 34
const byte D34 = 34 ;
#endif
#if NUM_DIGITAL_PINS > 35
const byte D35 = 35 ;
#endif
#if NUM_DIGITAL_PINS > 36
const byte D36 = 36 ;
#endif
#if NUM_DIGITAL_PINS > 37
const byte D37 = 37 ;
#endif
#if NUM_DIGITAL_PINS > 38
const byte D38 = 38 ;
#endif
#if NUM_DIGITAL_PINS > 39
const byte D39 = 39 ;
#endif
#if NUM_DIGITAL_PINS > 40
const byte D40 = 40 ;
#endif
#if NUM_DIGITAL_PINS > 41
const byte D41 = 41 ;
#endif
#if NUM_DIGITAL_PINS > 42
const byte D42 = 42 ;
#endif
#if NUM_DIGITAL_PINS > 43
const byte D43 = 43 ;
#endif
#if NUM_DIGITAL_PINS > 44
const byte D44 = 44 ;
#endif
#if NUM_DIGITAL_PINS > 45
const byte D45 = 45 ;
#endif
#if NUM_DIGITAL_PINS > 46
const byte D46 = 46 ;
#endif
#if NUM_DIGITAL_PINS > 47
const byte D47 = 47 ;
#endif
#if NUM_DIGITAL_PINS > 48
const byte D48 = 48 ;
#endif
#if NUM_DIGITAL_PINS > 49
const byte D49 = 49 ;
#endif
#if NUM_DIGITAL_PINS > 50
const byte D50 = 50 ;
#endif
#if NUM_DIGITAL_PINS > 51
const byte D51 = 51 ;
#endif
#if NUM_DIGITAL_PINS > 52
const byte D52 = 52 ;
#endif
#if NUM_DIGITAL_PINS > 53
const byte D53 = 53 ;
#endif
#if NUM_DIGITAL_PINS > 54
const byte D54 = 54 ;
#endif
#if NUM_DIGITAL_PINS > 55
const byte D55 = 55 ;
#endif
#if NUM_DIGITAL_PINS > 56
const byte D56 = 56 ;
#endif
#if NUM_DIGITAL_PINS > 57
const byte D57 = 57 ;
#endif
#if NUM_DIGITAL_PINS > 58
const byte D58 = 58 ;
#endif
#if NUM_DIGITAL_PINS > 59
const byte D59 = 59 ;
#endif
#if NUM_DIGITAL_PINS > 60
const byte D60 = 60 ;
#endif
#if NUM_DIGITAL_PINS > 61
const byte D61 = 61 ;
#endif
#if NUM_DIGITAL_PINS > 62
const byte D62 = 62 ;
#endif
#if NUM_DIGITAL_PINS > 63
const byte D63 = 63 ;
#endif
#if NUM_DIGITAL_PINS > 64
const byte D64 = 64 ;
#endif
#if NUM_DIGITAL_PINS > 65
const byte D65 = 65 ;
#endif
#if NUM_DIGITAL_PINS > 66
const byte D66 = 66 ;
#endif
#if NUM_DIGITAL_PINS > 67
const byte D67 = 67 ;
#endif
#if NUM_DIGITAL_PINS > 68
const byte D68 = 68 ;
#endif
#if NUM_DIGITAL_PINS > 69
const byte D69 = 69 ;
#endif
That's just cruel John
See who has no social life: https://forum.arduino.cc/index.php?action=stats
alto777:
Please tell us you used a program to write that header.
I used a spreadsheet to generate the names and numbers and then a text editor to turn the list into code.
You deserve another +1
johnwasser:
Here you go:
PinNames.h#if NUM_DIGITAL_PINS > 0
const byte D0 = 0 ;
#endif
...
#if NUM_DIGITAL_PINS > 69
const byte D69 = 69 ;
#endif
#if NUM_DIGITAL_PINS > 0
const byte D0 = 0 ;
#endif
...
#if NUM_DIGITAL_PINS > 69
const byte D69 = 69 ;
#endif
Oops.
oqibidipo:
Oops.
Oops indeed! Somehow I pasted the lines twice. I have edited the post to remove one of the copies. Thanks for catching that.
I'm relative new to the programming the arduino and have a problem associating the pin numbers to use in a sketch and the pin names (A0,D7,D5, etc etc).
Is there an #include statement that I can use to include these names vs pin numbers.
I tried to build a library function to do this but ran into problems.
Merged threads asking the same question
Why did you start a second thread ?
I'm new to using this forum. I inadvertently posted the question twice.
My mistake, will be more careful in future.
I'm using an Arduino nano . I prefer to use Pin Names (A0,A1,A2.... D4,D5,D6 ....etc,etc) instead of the corresponding Pin Numbers (19,20,21, etc, etc, etc).
I am still confused as to exactly what you want to do. For instance, the Arduino pin number for A0 is not 19, if that is what you meant, nor is it on pin 19 of the ATmega328 chip