Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long currentMillis;
- unsigned long duration_green = 2000;
- unsigned long duration_red = 2000;
- unsigned long time_1;
- unsigned long time_2;
- void setup()
- {
- pinMode(3,OUTPUT); // LED on lähtönä
- pinMode(4,OUTPUT);
- pinMode(7,INPUT); // Alustetaan kytkin tuloksi
- digitalWrite(3,HIGH); // Alkutilanne
- }
- void loop()
- {
- currentMillis = millis();
- if(digitalRead(7) == HIGH)
- {
- if(currentMillis > (time_1 + (duration_red)) && currentMillis < (duration_red+duration_green))
- {
- time_1 = currentMillis;
- digitalWrite(3,LOW);
- digitalWrite(4,HIGH);
- }
- if(currentMillis > (time_2 + (duration_red+duration_green)))
- {
- time_2 = currentMillis;
- digitalWrite(3,LOW);
- digitalWrite(4,LOW);
- }
- }
- else if(digitalRead(7) == LOW)
- {
- digitalWrite(3,LOW);
- digitalWrite(4,LOW);
- duration_red = duration_red+currentMillis;
- duration_green = duration_green+currentMillis;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement