Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Railroad crossing lights
- by DAVID
- */
- // constants won't change. Used here to set a pin number :
- const int ledPinP1 = 5; // the number of the LED pin
- const int ledPinP2 = 9; // the number of the LED pin
- const int ledPinF = 1; // the number of the LED pin
- const int switchPin = 6; // the number of the switch pin
- int switchState = 0; // variable for reading the switch status
- void setup() {
- pinMode(ledPinP1, OUTPUT); // initialize the LED pin as an output:
- pinMode(ledPinP2, OUTPUT);
- pinMode(ledPinF, OUTPUT);
- pinMode(switchPin, INPUT); // initialize the pushbutton pin as an input:
- }
- void loop()
- {
- switchState = digitalRead(switchPin); // read the state of the
- //pushbuttonvalue:
- if (switchState == HIGH) //if the switch on:
- {
- digitalWrite(ledPinF, LOW); //white LED off
- digitalWrite(ledPinP1, HIGH); //red1 LED on
- digitalWrite(ledPinP2, LOW); //red2 LED off
- delay(400); //wait 400ms
- digitalWrite(ledPinP1, LOW); //red1 LED off
- digitalWrite(ledPinP2, HIGH); //red2 LED on
- delay(400);
- }
- if(switchState == LOW) //if the switch off
- {
- digitalWrite(ledPinP1, LOW); //red1 LED off
- digitalWrite(ledPinP2, LOW); //red2 LED off
- digitalWrite(ledPinF, HIGH); //white LED on
- delay(500); //wait 500ms
- digitalWrite(ledPinF, LOW); //white LED off
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement