Advertisement
dfso

Semáforo usando Arduino

Jun 11th, 2017
3,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define VD1 8
  2. #define AM1 9
  3. #define VM1 10
  4.  
  5. #define VD2 5
  6. #define AM2 6
  7. #define VM2 7
  8.  
  9. void setup() {
  10.  
  11.     pinMode(VD1, OUTPUT);
  12.     pinMode(AM1, OUTPUT);
  13.     pinMode(VM1, OUTPUT);
  14.  
  15.     pinMode(VD2, OUTPUT);
  16.     pinMode(AM2, OUTPUT);
  17.     pinMode(VM2, OUTPUT);
  18. }
  19.  
  20. void loop() {
  21.  
  22.     digitalWrite(VD1, HIGH);
  23.     digitalWrite(VM2, HIGH);
  24.     delay(7000);
  25.     digitalWrite(VD1, LOW);
  26.     piscarVerde(VD1, 3);
  27.    
  28.     digitalWrite(AM1, HIGH);
  29.     delay(5000);
  30.     digitalWrite(AM1, LOW);
  31.    
  32.     digitalWrite(VM1, HIGH);
  33.     digitalWrite(VM2, LOW);
  34.    
  35.     digitalWrite(VD2, HIGH);
  36.     delay(7000);
  37.     digitalWrite(VD2, LOW);
  38.     piscarVerde(VD2, 3);
  39.    
  40.     digitalWrite(AM2, HIGH);
  41.     delay(5000);
  42.     digitalWrite(AM2, LOW);
  43.     digitalWrite(VM1, LOW);
  44. }
  45.  
  46. // faz o led piscar durante o intervalo passado como parâmetro
  47. void piscarVerde(int pin, int seconds) {
  48.  
  49.     for(int i=0; i<seconds; i++) {
  50.         digitalWrite(pin, HIGH);
  51.         delay(500);
  52.         digitalWrite(pin, LOW);
  53.         delay(500);
  54.     }
  55.        
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement