Since you are in a loop, this will blink indicatorleft whenever leftbutton is held low:
if (digitalRead(leftbutton) == LOW)
{
digitalWrite(indicatorleft, HIGH); //Blink LED on every time through loop
delay(200);
digitalWrite(indicatorleft,LOW); //Blink LED off every time through loop
delay(200);
}
You could use an else-statement here:
if (digitalRead(leftbutton) ==HIGH)
{
digitalWrite(indicatorleft, LOW);
}
Because if leftbutton is not low, we know it's high...
else
{
digitalWrite(indicatorleft, LOW);
}
There is one slight difference though.... The if-else statement checks the state of leftbutton before the delay. Your way, you are reading the leftbutton again after the delays
}
The way you wrote your sketch the RIGHT indicator will only blink if BOTH buttons are ON. Removing the 'else' in the middle should have fixed it. If that did not fix it you must have made other changes that broke it in a different way/
void loop() {
{
// If the LEFT button is ON...
if (digitalRead(leftbutton) == LOW) {
// ... turn the LEFT indicator on and off
digitalWrite(indicatorleft, HIGH);
delay(200);
digitalWrite(indicatorleft, LOW);
delay(200);
}
// If the LEFT button is OFF...
if (digitalRead(leftbutton) == HIGH) {
// ... turn LEFT indicator off
digitalWrite(indicatorleft, LOW);
} else { // If the LEFT button is ON...
// ... AND the RIGHT button is ON ...
if (digitalRead(rightbutton) == LOW) {
// ... turn the RIGHT indicator on and off
digitalWrite(indicatorright, HIGH);
delay(200);
digitalWrite(indicatorright, LOW);
delay(200);
}
// If the RIGHT button is OFF...
if (digitalRead(rightbutton) == HIGH) {
// ... turn RIGHT indicator off
digitalWrite(indicatorright, LOW);
}
}
}
lcd.setCursor(0, 1);
//print mph once a second
displayMPH();
delay(1000);
}