const byte HeadlightButton = 3 ; const byte BreaklightButton = 4 ; const byte LeftButton = 5 ; const byte RightButton = 6 ; const byte Headlight = 7 ; const byte Breaklight = 8; const byte Left = 9 ; const byte Right = 10 ; unsigned long LeftPreMillis ; unsigned long RightPreMillis ; const int interval = 350 ; byte LeftButtonPrevious = LOW ; byte RightButtonPrevious = LOW ; byte HeadButtonPrevious = LOW ; byte RightButtonCurrent ; byte LeftButtonCurrent ; byte HeadButtonCurrent ; byte BreakButtonCurrent ; byte HeadState = HIGH ; byte LeftState = LOW ; byte RightState = LOW ; byte LeftLedState = LOW; byte RightLedState = LOW; unsigned long a,b; void setup() { //initialization of the input pins pinMode(HeadlightButton,INPUT); pinMode(BreaklightButton,INPUT); pinMode(LeftButton,INPUT); pinMode(RightButton,INPUT); //initialization of the output pins pinMode(Headlight,OUTPUT); pinMode(Breaklight,OUTPUT); pinMode(Left,OUTPUT); pinMode(Right,OUTPUT); //making sure all of the lights are turned off digitalWrite(Left,HIGH); digitalWrite(Headlight,HIGH); digitalWrite(Breaklight,HIGH); digitalWrite(Right,HIGH); //uncomment the following if you are using a pro micro which is a bit on the overkill side /* pinMode(15,OUTPUT); digitalWrite(15,HIGH);//using the pin 15 as a 5v output pin or the vc pin or you can leave it out and use the vcc pin with the input instead */ } void loop(){ unsigned long CurrentMillis = millis();//getting the current millis //Checking each button state (HIGH or LOW) HeadButtonCurrent = digitalRead(HeadlightButton); LeftButtonCurrent = digitalRead(LeftButton); RightButtonCurrent = digitalRead(RightButton); BreakButtonCurrent = digitalRead(BreaklightButton); if(BreakButtonCurrent == HIGH) { digitalWrite(Breaklight,LOW);//checking if the breaklight button is high or not and if high turn the breaklight on } else { digitalWrite(Breaklight,HIGH);//if the breaklight button is low turning the breaklight off } if(HeadButtonCurrent == HIGH && HeadButtonPrevious == LOW)//checking if the headlight button is high and the previous headlight button was off or not { HeadState = !HeadState ;//changing the state of the headight if high then it becomes low and if low it becomes high digitalWrite(Headlight,HeadState);//applying the same } HeadButtonPrevious = HeadButtonCurrent;//headlight button current is now headlight button previous if(LeftButtonCurrent==HIGH && LeftButtonPrevious==LOW)//checking if the left button current is high and the left button previous is low or not { LeftState = !LeftState;//if left state was high it turns it into low and if it was low it turns it into high } LeftButtonPrevious = LeftButtonCurrent;//left button current is now left button previous if(LeftState==HIGH)//checking if left state is high or not { digitalWrite(Left,LeftLedState);//appling the let led state to the left left a = CurrentMillis-LeftPreMillis; if(a >= interval)//checking if current milli - previous left millis is more than or equal to interval or not { LeftLedState=!LeftLedState;//changing left led state to opposite state LeftPreMillis = CurrentMillis;//now current millis is left previous millis } } if(RightButtonCurrent==HIGH && RightButtonPrevious==LOW) { RightState = !RightState; digitalWrite(Right,HIGH); } RightButtonPrevious = RightButtonCurrent; if(RightState==HIGH) { digitalWrite(Right,RightLedState); b = CurrentMillis-RightPreMillis; if(b>=interval) { RightLedState=!RightLedState; RightPreMillis = CurrentMillis; } } }