Advertisement
Guest User

Arduino Street Light

a guest
Feb 23rd, 2016
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. int button = 2; // switch is on pin 2
  2. int buttonValue = 0; // switch defaults to 0 or LOW
  3. int red = 13;
  4. int yellow = 12;
  5. int green = 11;
  6.  
  7. void setup(){
  8. pinMode(red,OUTPUT);
  9. pinMode(yellow,OUTPUT);
  10. pinMode(green,OUTPUT);
  11. pinMode(button,INPUT);
  12. digitalWrite(green,HIGH);
  13. }
  14.  
  15. void changeLights(){
  16. // green off, yellow for 3 seconds
  17. digitalWrite(green,LOW);
  18. digitalWrite(yellow,HIGH );
  19. delay(3000);
  20.  
  21. // turn off yellow, then turn red on for 5 seconds
  22. digitalWrite(yellow,LOW);
  23. digitalWrite(red,HIGH);
  24. delay(5000);
  25.  
  26. // red and yellow on for 2 seconds (red is already on though)
  27. digitalWrite(yellow,HIGH);
  28. delay(2000);
  29.  
  30. // turn off red and yellow, then turn on green
  31. digitalWrite(yellow,LOW);
  32. digitalWrite(red,LOW);
  33. digitalWrite(green,HIGH);
  34. }
  35.  
  36. void loop(){
  37. // read the value of the switch
  38. buttonValue = digitalRead(button);
  39. // if the switch is HIGH, ie. pushed down – change the lights!
  40. if (buttonValue == HIGH){
  41. changeLights();
  42. delay(2000);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement