I am connecting 4 buttons to an arduino pro
At this moment I use the analog inputs, but no matter what the same problem keeps appearing: one of the buttons will not be detected. I have used my multimeter to ensure that it functions well (it becomes low when I press it):
Below the code that I use:
int btnred, btnyel, btngrn, btnblu; // buttons
int pressed = LOW;
void setup() {
// setting the pins
btnred = 17;
btnyel = 16;
btnblu = 15;
btngrn = 14;
pinMode(btnred, INPUT);
digitalWrite(btnred, HIGH);
pinMode(btnyel, INPUT);
digitalWrite(btnyel, HIGH);
pinMode(btngrn, INPUT);
digitalWrite(btngrn, HIGH);
pinMode(btnblu, INPUT);
digitalWrite(btnblu, HIGH);
//Serial.begin(9600);
}
void loop() {
int redval, yelval, bluval, grnval;
redval = digitalRead(btnred);
yelval = digitalRead(btnyel);
bluval = digitalRead(bluval);
grnval = digitalRead(btngrn);
if (redval == pressed) {
lc.setDigit(0,3,1,false);
//Serial.println("Yellow");
} else {
lc.setDigit(0,3,0,false);
}
if (bluval == pressed) {
lc.setDigit(0,1,1,false);
//Serial.println("Yellow");
} else {
lc.setDigit(0,1,0,false);
}
if (grnval == pressed) {
lc.setDigit(0,0,1,false);
//Serial.println("Yellow");
} else {
lc.setDigit(0,0,0,false);
}
if (yelval == pressed) {
lc.setDigit(0,2,1,false);
//Serial.println("Yellow");
} else {
lc.setDigit(0,2,0,false);
}
delay(200);
}
B.t.w. I also seem to get crap when I use the terminal. I have tred using other pins, etc etc, then the blue button might function but an other one will fail to report when it is pressed.