More digital pins
There are times when we need more digital pins on the Arduino without any other external components. An Arduino Uno has 14 digital pins, from 0 to 14, right? Wrong! It actually has 20. The analog in ports can at all times be used as digital ports, and they have all the functionality of normal digital ports.
Tip
A word of caution: pins 0 and 1 are the UART ports used for programming need to take extra care about what we connect there, because when we are programming the board, those pins will switch from HIGH to LOW thousands of times.
Getting ready
Just one ingredient is needed for this recipe—an Arduino Board connected to a computer via USB.
How to do it…
The following code shows how to use pins A0
and A1
as normal digital pins:
void setup(){ pinMode(A0, OUTPUT); pinMode(A1, OUTPUT); } void loop(){ digitalWrite(A0, HIGH); digitalWrite(A1, LOW); delay(500); digitalWrite(A0, LOW); digitalWrite(A1, HIGH); delay(500); }
How it works…
Internally, all pins on Arduino...