Advertisement
makispaiktis

ArduinoBasics - 1. Traffic Lights Code

Mar 20th, 2021 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int redPin = 11;
  2. int orangePin = 10;
  3. int greenPin = 9;
  4.  
  5. void setup()
  6. {
  7.   pinMode(redPin, OUTPUT);
  8.   pinMode(orangePin, OUTPUT);
  9.   pinMode(greenPin, OUTPUT);
  10. }
  11.  
  12. void loop()
  13. {
  14.   // I will open the LED serially
  15.   // 1st "red" will be HIGH for some seconds, then "orange"
  16.   // for a little time and then "green"
  17.   // Step 1
  18.   digitalWrite(redPin, HIGH);
  19.   digitalWrite(orangePin, LOW);
  20.   digitalWrite(greenPin, LOW);
  21.   delay(3000);
  22.   // Step 2
  23.   digitalWrite(redPin, LOW);
  24.   digitalWrite(orangePin, HIGH);
  25.   digitalWrite(greenPin, LOW);
  26.   delay(1000);
  27.   // Step 1
  28.   digitalWrite(redPin, LOW);
  29.   digitalWrite(orangePin, LOW);
  30.   digitalWrite(greenPin, HIGH);
  31.   delay(2000);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement