Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. /*
  2. Railroad crossing lights
  3. by DAVID
  4. */
  5. // constants won't change. Used here to set a pin number :
  6. const int ledPinP1 = 5; // the number of the LED pin
  7. const int ledPinP2 = 9; // the number of the LED pin
  8. const int ledPinF = 1; // the number of the LED pin
  9. const int switchPin = 6; // the number of the switch pin
  10. int switchState = 0; // variable for reading the switch status
  11.  
  12. void setup() {
  13.  
  14. pinMode(ledPinP1, OUTPUT); // initialize the LED pin as an output:
  15. pinMode(ledPinP2, OUTPUT);
  16. pinMode(ledPinF, OUTPUT);
  17. pinMode(switchPin, INPUT); // initialize the pushbutton pin as an input:
  18. }
  19.  
  20. void loop()
  21. {
  22. switchState = digitalRead(switchPin); // read the state of the
  23. //pushbuttonvalue:
  24. if (switchState == HIGH) //if the switch on:
  25. {
  26. digitalWrite(ledPinF, LOW); //white LED off
  27. digitalWrite(ledPinP1, HIGH); //red1 LED on
  28. digitalWrite(ledPinP2, LOW); //red2 LED off
  29. delay(400); //wait 400ms
  30. digitalWrite(ledPinP1, LOW); //red1 LED off
  31. digitalWrite(ledPinP2, HIGH); //red2 LED on
  32. delay(400);
  33. }
  34. if(switchState == LOW) //if the switch off
  35. {
  36. digitalWrite(ledPinP1, LOW); //red1 LED off
  37. digitalWrite(ledPinP2, LOW); //red2 LED off
  38. digitalWrite(ledPinF, HIGH); //white LED on
  39. delay(500); //wait 500ms
  40. digitalWrite(ledPinF, LOW); //white LED off
  41. delay(500);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement