Created
June 29, 2014 18:47
-
-
Save evangilo/b2a834f80475f41ee49d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //autor: evangilo | |
| const int buttonPin = 1; | |
| const int greenLedPin = 13; | |
| const int yellowLedPin = 12; | |
| const int redLedPin = 11; | |
| const int redLedPedestrianPin = 10; | |
| const int greenLedPedestrianPin = 9; | |
| int buttonState = 0; | |
| void setup() { | |
| // inicializa a saida dos leds | |
| pinMode(redLedPin, OUTPUT); | |
| pinMode(yellowLedPin, OUTPUT); | |
| pinMode(greenLedPin, OUTPUT); | |
| pinMode(greenLedPedestrianPin, OUTPUT); | |
| pinMode(redLedPedestrianPin, OUTPUT); | |
| // inicializa a entrada do botão | |
| pinMode(buttonPin, INPUT); | |
| } | |
| void loop(){ | |
| digitalWrite(redLedPedestrianPin, HIGH); | |
| if(digitalRead(buttonPin) == HIGH){ | |
| pedestriamSemaphore(); | |
| } | |
| else { | |
| yellowLed(); | |
| } | |
| redLed(); | |
| if(digitalRead(buttonPin) == HIGH){ | |
| pedestriamSemaphore(); | |
| } | |
| else { | |
| greenLed(); | |
| } | |
| } | |
| void redLed() { | |
| digitalWrite(redLedPin, HIGH); | |
| digitalWrite(redLedPedestrianPin, LOW); | |
| digitalWrite(greenLedPedestrianPin, HIGH); | |
| delay(5000); | |
| digitalWrite(redLedPedestrianPin, HIGH); | |
| digitalWrite(greenLedPedestrianPin, LOW); | |
| digitalWrite(redLedPin, LOW); | |
| } | |
| void yellowLed() { | |
| for(int i = 0; i < 6; i++) { | |
| digitalWrite(yellowLedPin, HIGH); | |
| delay(500); | |
| digitalWrite(yellowLedPin, LOW); | |
| delay(500); | |
| } | |
| } | |
| void greenLed() { | |
| digitalWrite(greenLedPin,HIGH); | |
| delay(5000); | |
| digitalWrite(greenLedPin, LOW); | |
| } | |
| void pedestriamSemaphore() { | |
| digitalWrite(redLedPedestrianPin, LOW); | |
| digitalWrite(redLedPin, HIGH); | |
| digitalWrite(greenLedPin, LOW); | |
| digitalWrite(yellowLedPin, LOW); | |
| digitalWrite(greenLedPedestrianPin, HIGH); | |
| delay(5000); | |
| digitalWrite(greenLedPedestrianPin, LOW); | |
| digitalWrite(redLedPin, LOW); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment