mpmcws

Traffic Light

Sep 20th, 2018
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Traffic Light
  2. // September 2018. MPMC Workshop
  3. // Open source. Have a good fun!
  4. //https://pastebin.com/xz7icMbD
  5. int RL = 7; // int + variable name + = + pin number + ;
  6. int YL = 6;
  7. int GL = 5;
  8. //
  9. int RR = 4;
  10. int YR = 3;
  11. int GR = 2;
  12. //
  13. void setup() {
  14.   pinMode (RL, OUTPUT); // pinMode + ( + variable number + , + type pin + ) + ;
  15.   pinMode (YL, OUTPUT);
  16.   pinMode (GL, OUTPUT);
  17.   //
  18.   pinMode (RR, OUTPUT);
  19.   pinMode (YR, OUTPUT);
  20.   pinMode (GR, OUTPUT);
  21.   //
  22. }
  23. // put all the low output pins. The tension will be zero.
  24. void loop() {
  25.   digitalWrite (RL, LOW); // digitalWrite + ( + variable name + , + pin high or low + ) + ;
  26.   digitalWrite (YL, LOW);
  27.   digitalWrite (GL, LOW);
  28.   digitalWrite (RR, LOW);
  29.   digitalWrite (YL, LOW);
  30.   digitalWrite (GR, LOW);
  31.   // let's start the traffic light
  32.   //we turn on the two green LEDs
  33.   digitalWrite (GL, HIGH);
  34.   digitalWrite (GR, HIGH);
  35.   //the LEDs remain on for 4 seconds
  36.   delay (4000);
  37.   //yellow LEDs on and green LEDs on
  38.   digitalWrite (YL, HIGH);
  39.   digitalWrite (YR, HIGH);
  40.   delay (2000);
  41.   //
  42.   digitalWrite (YL, LOW);
  43.   digitalWrite (GL, LOW);
  44.   digitalWrite (YR, LOW);
  45.   digitalWrite (GR, LOW);
  46.   //
  47.   digitalWrite (RL, HIGH);
  48.   digitalWrite (RR, HIGH);
  49.   delay (4000);
  50. }
RAW Paste Data