Hey, im getting weird results trying to get serial prints from 2 buttons
the two buttons are on my breadboard, one is left and one is right (the problem isnt in build)
my code:
const int buttonPin = 11; //set pin for button 1
const int buttonPin2 = 12; // set pin for button 2
int buttonState = 0; //set the state of the button to anything which isnt HIGH
int buttonState2 = 0;
void setup (){
-
pinMode (buttonPin, INPUT); //SET BOTH BUTTONS IS INPUT*
-
pinMode (buttonPin2, INPUT);*
-
Serial.begin(9600); // add serial commands*
}
void loop (){ -
buttonState=digitalRead (buttonPin); // WRITE DOWN THE STATE OF EACH BUTTON*
-
buttonState2=digitalRead (buttonPin2);*
-
if (buttonState==LOW){ // CHECK BUTTON 1*
-
//button 1 is pressed!*
-
Serial.println("Right");*
-
}*
else if (buttonState2==LOW){ //CHECK BUTTON 2 -
//button 2 is pressed!*
-
Serial.println("Left");*
-
}*
}
what im receiving is an incredible amount of "right" and "left" and the same time , even thought im not clicking the buttons. rewrote the code several times but nothing helped
again, im tring to get a serial messege "right" when the right button is clicked and "left" when the left one is clicked.
can someone tell me what am i doing wrong?
any help will be totally appreciated, Amit.