Recently I’ve just found out that I can actually turn my Analog input pins into Digital Inputs or Outputs. It’s really simple.
Usually for the digital pins, we write instructions such as digitalWrite(13, HIGH). To do that with analog pins, simply use digits 14 to 19.
Pin 14 being Analog 0, 15 being Analog 1 and so on. Or you can just write digitalWrite(A0, HIGH).
Here’s a simple sketch to test that out. Turn on an LED that’s connected to Analog 0.
What about Digital Inputs? Just treat the Analog pins like they’re digital by using pins 14 to 19 or A0 to A5.
I wrote a sample sketch to test whether the Analog pins can be turned to Digital inputs. When the button is pressed, the LED will light up for two seconds.
No digital pins were used in these tests