Created
June 21, 2018 18:47
-
-
Save georgebrindeiro/82e09c257666ef47a5a63b3390a3fa13 to your computer and use it in GitHub Desktop.
Semáforo com Cancela (Raphael Beltrão, 6A, Seriös 2018)
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
#include <Servo.h> | |
Servo myservo; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(2,INPUT_PULLUP); | |
pinMode(3,OUTPUT); | |
pinMode(4,OUTPUT); | |
pinMode(5,OUTPUT); | |
pinMode(6,OUTPUT); | |
pinMode(7,OUTPUT); | |
myservo.attach(8); | |
} | |
void loop() { | |
int d = 2000; | |
int button = digitalRead(2); | |
// carros passando, pedestre esperando | |
digitalWrite(7,HIGH); | |
digitalWrite(6,LOW); | |
digitalWrite(5,LOW); | |
digitalWrite(4,HIGH); | |
digitalWrite(3,LOW); | |
// cancela aberta | |
myservo.write(0); | |
if(button == LOW) | |
{ | |
//sinal amarelo | |
digitalWrite(7,LOW); | |
digitalWrite(6,HIGH); | |
digitalWrite(5,LOW); | |
digitalWrite(4,HIGH); | |
digitalWrite(3,LOW); | |
delay(5000); | |
//sinal vermelho | |
// cancela fechada | |
myservo.write(90); | |
digitalWrite(7,LOW); | |
digitalWrite(6,LOW); | |
digitalWrite(5,HIGH); | |
digitalWrite(4,HIGH); | |
digitalWrite(3,LOW); | |
delay(1000); | |
//VERDE PEDESTRE | |
digitalWrite(7,LOW); | |
digitalWrite(6,LOW); | |
digitalWrite(5,HIGH); | |
digitalWrite(4,LOW); | |
digitalWrite(3,HIGH); | |
delay(5000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment