Good morning dear fellas,
I'd like to check the status of an inport port when I press a button, but let me descrive you my constraits.
I have to use as input digital ports these analogic ports from A0 to A7.
Analogic port A8 is used as digital output.
I have 8 switches, 1 wire of each switches is connected to A8 which has a 5v as output, the others wires are connected to A0 till A7.
I'm pretty sure I'm doing something wrong, my apologize for my incompentece, I'm trying to learn.
Here my script, first the consts:
const int swA0 = A0;
const int swA1 = A1;
const int swA2 = A2;
const int swA3 = A3;
const int swA4 = A4;
const int swA5 = A5;
const int swA6 = A6;
const int swA7 = A7;
const int VCC = A8;
then the setup method:
void setup() {
pinMode(swA0, INPUT); //A0
pinMode(swA1, INPUT);
pinMode(swA2, INPUT);
pinMode(swA3, INPUT);
pinMode(swA4, INPUT);
pinMode(swA5, INPUT);
pinMode(swA6, INPUT);
pinMode(swA7, INPUT); //A7
pinMode(VCC, OUTPUT);//A8
digitalWrite(VCC, HIGH);
Serial.begin(9600);
Serial.println("START - Init device");
}
As you can see I see from A0 to A7 as input and the A8 as output and then I set HIGH the port A8. Indeed I can measure more than 4 volt from A8 port.
Now the loop method:
void loop() {
delay(1000);
if (digitalRead(swA0) == HIGH)
Serial.println("A0 CLOSE");
if(digitalRead(swA1) == HIGH)
Serial.println("A1 CLOSE");
if (digitalRead(swA2) == HIGH)
Serial.println("A2 CLOSE");
if(digitalRead(swA3) == HIGH)
Serial.println("A3 CLOSE");
if (digitalRead(swA4) == HIGH)
Serial.println("A4 CLOSE");
if(digitalRead(swA5) == HIGH)
Serial.println("A5 CLOSE");
if (digitalRead(swA6) == HIGH)
Serial.println("A6 CLOSE");
if(digitalRead(swA7) == HIGH)
Serial.println("A7 CLOSE");
}
So I'm expecting that when I close as example A0 with A8, with a switch or just connecting a wire, I read A0 CLOSE.
Well actually I read it but also A1 CLOSE multiple times, see the output log for few second.
A0 CLOSE
A1 CLOSE
A0 CLOSE
A1 CLOSE
A0 CLOSE
A1 CLOSE
A0 CLOSE
A1 CLOSE
A0 CLOSE
A0 CLOSE
A0 CLOSE
I feel lost
I appreciate any help, thanks a lot