Hello,
This is my first posting and I am a beginner using Arduino.
I have a project where I have used all the digital I/O pins. I need one more digital I/O pin and I have been trying to use A0 thru A4 as digital input/output pins.
Can this be done?
First off, I have been able to use A0 as a digital output, but I can't get A1 thru A4 to output Low or HIGH signals.
I have tried pinMode 0,1,2,3...and 14, 15, 16, 17 and of course A0, A1, A2, A3
No luck.
I have even tried using digitalRead/digitalWrite and analogRead and digitalWrite.
I have the Trinket Pro 5V board.
What am I doing wrong?
Using Analog Pins as Digital Outputs
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Using Analog Pins as Digital Outputs
Yes, that should work.
This should set A1 high for example:
How you determining if a pin is high/low?
This should set A1 high for example:
Code: Select all
void setup() {
pinMode(15, OUTPUT);
digitalWrite(15, HIGH);
}
void loop() {
}
- vcholman
- Posts: 3
- Joined: Thu Aug 12, 2021 4:39 pm
Re: Using Analog Pins as Digital Outputs
Almost, but still not working.
I have a push button connected to A1 and A2 is it's output.
This an example of my code
I'm not sure if A1 is monitoring the button status and A2 never changes state.
Can you help?
I have a push button connected to A1 and A2 is it's output.
This an example of my code
Code: Select all
//Button6
int MainPwrButton6=A1;
int MainPwr6=A2;
void setup ()
{
pinMode (MainPwrButton6,INPUT);
pinMode (MainPwr6,OUTPUT);
void checkMainPwrButton6 () {
{
reading = digitalRead (MainPwrButton6);
if (reading == LOW && previous1 == HIGH && millis () - time > debounce) {
if (state1 == LOW)
state1 = HIGH;
else
state1 = LOW;
time = millis();
}
digitalWrite (MainPwr6, state6);
previous1 = reading;
}
}
void loop ()
{
checkMainPwrButton6();
}
Can you help?
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Using Analog Pins as Digital Outputs
For inputs, try just printing state in a loop to verify functionality. Use pull up/downs as need to avoid floating inputs.
For outputs, can either attach an LED or measure voltage with a DMM as a way to verify.
For outputs, can either attach an LED or measure voltage with a DMM as a way to verify.
- vcholman
- Posts: 3
- Joined: Thu Aug 12, 2021 4:39 pm
Re: Using Analog Pins as Digital Outputs
All,
Solved my problem. There were 2 syntax errors in my code.
A0 thru A4 are now working as digital inputs and outputs.
Thanks,
Solved my problem. There were 2 syntax errors in my code.
A0 thru A4 are now working as digital inputs and outputs.
Thanks,
Please be positive and constructive with your questions and comments.