When passing the pin number in pinMode its possible to use A0 - A7, does it apply only to that methode? How can pinMode expect a number (is it int?) type in case of digital pin another (is it then string?) in case of analog pin? I want to use that in my class methode, is there a way to use that and have my code more readable or should I use the pin numbers? P.S. I have tried to read the source code but I don't understand the uin8_t (I know its a byte, but not how it can understand A5 as an int)
Tnx a lot
1 Answer 1
pinMode is actually declared as void pinMode(uint8_t, uint8_t);
in arduino.h
A0 is a defined as a number (somewhere depending on the actual hardware), on an Uno/Nano it translates to 14, and when executing pinMode it translates to the appopriate bit in the correct DDRx register.
-
On an atmega328 Arduino pin 14 ( or A0 ) is directed to PORTA bit 0, which can be used as a digital I/O or alternatively as an ADC channel.DataFiddler– DataFiddler2019年11月24日 13:31:34 +00:00Commented Nov 24, 2019 at 13:31
-
The ATmega328 doesn't have a port 0. pin 14 (A0) is PC0.Edgar Bonet– Edgar Bonet2019年11月24日 19:05:48 +00:00Commented Nov 24, 2019 at 19:05
-
Correct: PORTC Bit 0 Thanks. In the DIP28 atmega328P-PU its Pin 23DataFiddler– DataFiddler2019年11月24日 22:14:25 +00:00Commented Nov 24, 2019 at 22:14