Hi Friends,
Working on my project here, decided to add a button to get into setup, and use the two others to go up and down. It's easier. But now I run these two if loops, the first one works fine, one click gives me one increment, but as soon as I add the down counter, it just keeps on ticking down. No matter if the button is HIGH or LOW, and if I push the + button, the counter goes up one and back down and down.
I checked the wires, buttons work fine, 0v and 5v for both, the button2 is LOW.
Code:
void loop()
{
button5 = digitalRead(buttonPin5);
if(button5 == HIGH); //button5 is held high for the time being.
{
button4 = digitalRead(buttonPin4); // start loop
button2 = digitalRead(buttonPin2);
if(button2 == LOW && button4 == LOW) //both low, nothing happening
{
delay(500);
}
if(button4 == HIGH) //button4 HIGH count up
{
digitalWrite(13, HIGH); //LED
yh++;
delay(200);
Serial.println(yh, DEC);
digitalWrite(13, LOW);
}
if(button2 == HIGH); //button2 HIGH count down, here's the problem.
{
yh--;
delay(200);
digitalWrite(13, HIGH); //LED
Serial.println(yh, DEC);
digitalWrite(13, LOW);
}
}
}