belrey10

Lesson #7: Traffic Controller

Nov 4th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int red = 8;
  2. int yellow = 9;
  3. int green = 10;
  4.  
  5. void setup() {
  6.   // put your setup code here, to run once:
  7.     pinMode(red, OUTPUT);
  8.     pinMode(yellow, OUTPUT);
  9.     pinMode(green, OUTPUT);
  10. }
  11.  
  12. void loop() {
  13.   // put your main code here, to run repeatedly:
  14.     digitalWrite(green, LOW);
  15.     digitalWrite(yellow, HIGH);
  16.     delay(3000);
  17.  
  18.     // turn off yellow, then turn red on for 5 seconds
  19.     digitalWrite(yellow, LOW);
  20.     digitalWrite(red, HIGH);
  21.     delay(5000);
  22.  
  23.     // red and yellow on for 2 seconds (red is already on though)
  24.     digitalWrite(yellow, HIGH);
  25.     delay(2000);
  26.  
  27.     // turn off red and yellow, then turn on green
  28.     digitalWrite(yellow, LOW);
  29.     digitalWrite(red, LOW);
  30.     digitalWrite(green, HIGH);
  31.     delay(3000);
  32. }
Add Comment
Please, Sign In to add comment