Hi,
I'm new with Arduino. I have project to upgrade my son's Power Wheels with turn signal.
I used code from Moiraredneck's post
const int leftButton = 2;
const int leftLedPin = 10;
boolean lLedState = LOW;
boolean previousButtonState = HIGH;
boolean lButtonState = LOW;
boolean serialCheck = LOW;
long duration = 0;
unsigned long previousMillis = 0;
// constants won't change : how long LED is on
const long interval = 500;
void setup()
{
Serial.begin(9600);
// set the digital pin as output:
pinMode(leftLedPin, OUTPUT);
pinMode(leftButton, INPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval && lButtonState == HIGH )
{
previousMillis = currentMillis;
// Serial.println(buttonState);
// if(lButtonState == HIGH)
// {
if (lLedState == LOW)
{
lLedState = HIGH;
Serial.println("led set high");
}
else
{
lLedState = LOW;
}
// }
if (millis() >= duration)
{
Serial.println("duration completed");
previousButtonState = lButtonState;
lButtonState = LOW;
lLedState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(leftLedPin, ledState);
}
if(digitalRead(leftButton) == HIGH)
{
if(previousButtonState == HIGH)
{
Serial.println("pressed");
// Serial.println(currentMillis);
lButtonState = HIGH;
}
else
{
buttonState = LOW;
}
delay(150); //debouncing
duration = millis() + 5000; // How long the loop lasts
}
}
This works for one side (left),i know how add more LEDs to this, but my problem is I don't know how to code for another button for right side.