I'm new in arduino. Trying to build custom motorcycle lights control.
Basicly i need one push button to do 3 functions.
1 click turn on LED1 blinking till press one more time
2 clicks turn on LED2 blinking till press one more time
3 long press turn on LED1 and LED2 to blink till next long press.
const byte buttonPin = 7;
const byte ledPin = 13;
boolean flashing = false;
byte currentButtonState = HIGH;
byte previousButtonState = HIGH;
unsigned long currentTime;
unsigned long onoffStarted;
long flashPeriod = 1000;
void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop()
{
currentButtonState = digitalRead(buttonPin);
if (currentButtonState != previousButtonState && currentButtonState == LOW) //button has become pressed
{
flashing = !flashing;
}
previousButtonState = currentButtonState; //save the button state for the next check
if (flashing)
{
currentTime = millis();
if (currentTime - onoffStarted > flashPeriod) //if the flash period ended ?
{
digitalWrite(ledPin, !digitalRead(ledPin)); //flip the state of the LED
onoffStarted = currentTime; //save the time when it occured
}
}
else
{
digitalWrite(ledPin, HIGH); //force the LED off if not flashing
}
}
I trying to understand from basics.. so trying to play first with one function, and its working fine. how i can set second function to button for turning on second LED?