SHARE
TWEET

Full Circle #48 - Arduino

a guest Apr 8th, 2011 395 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Connect one lead of the push button to 5 volts and the other to digital pin 2 and a 10K Ohm
  2.    pull-down resistor.  Use 220 Ohm resistors to connect each of the LEDs to pins 8-12. The
  3.    buzzer requires two 150 Ohm resistors in parallel to deliver a max of 2 volts to the 3-volt buzzer.
  4. */
  5.  
  6. const int PED_BUT = 2;
  7. const int PED_BUZ = 3;
  8. const int PED_GRE = 8;
  9. const int PED_RED = 9;
  10. const int TRAF_GRE = 10;
  11. const int TRAF_YEL = 11;
  12. const int TRAF_RED = 12;
  13.  
  14. void setup(){                       // mandatory procedure--set pin modes
  15.     pinMode(PED_BUT, INPUT);
  16.     pinMode(PED_BUZ, OUTPUT);
  17.     pinMode(PED_GRE, OUTPUT);
  18.     pinMode(PED_RED, OUTPUT);
  19.     pinMode(TRAF_GRE, OUTPUT);
  20.     pinMode(TRAF_YEL, OUTPUT);
  21.     pinMode(TRAF_RED, OUTPUT);
  22. }
  23.  
  24. void loop(){                        // mandatory procedure--main program
  25.     digitalWrite(TRAF_GRE, HIGH);   // default GRE traffic light -- default at start
  26.     delay(6000);                    // delay 6 sec.
  27.     haltTraffic();
  28.     delay(10000);                   // delay 10 sec.
  29.     changeTrafficGRE();
  30.     for(int i=0;i<50;i++){          // test for BUT pushed
  31.         if(digitalRead(PED_BUT)==HIGH)
  32.             break;
  33.         delay(400);                 // delay 0.4 sec.
  34.     }
  35. }
  36.  
  37. void haltTraffic(){                 // halt traffic with Red, allow pedestrians with GRE with BUZ
  38.     changeTrafficRed();    
  39.     delay(1000);                    // delay 1 sec.
  40.     digitalWrite(PED_RED, LOW);
  41.     digitalWrite(PED_GRE, HIGH);
  42. }
  43.  
  44. void changeTrafficRed(){            // change traffic lights from GRE to YEL and then to red
  45.     digitalWrite(TRAF_GRE, LOW);
  46.     digitalWrite(TRAF_YEL, HIGH);
  47.     delay(5000);                    // delay 5 sec.
  48.     digitalWrite(TRAF_YEL, LOW);
  49.     digitalWrite(TRAF_RED, HIGH);
  50. }
  51.  
  52. void changeTrafficGRE(){            //  halt pedestrian traffic with red and sound, allow traffic with GRE
  53.     digitalWrite(PED_GRE, LOW);
  54.     for(int i=0;i<8;i++){
  55.         digitalWrite(PED_RED, LOW);
  56.         digitalWrite(PED_BUZ, HIGH);
  57.         delay(500);                 // delay 0.5 sec.
  58.         digitalWrite(PED_RED, HIGH);          
  59.         digitalWrite(PED_BUZ, LOW);
  60.         delay(500);                 // delay 0.5 sec.
  61.     }
  62.     delay(3000);                    // delay 3 sec.
  63.     digitalWrite(TRAF_RED, LOW);  
  64.     digitalWrite(TRAF_GRE, HIGH);  
  65. }
RAW Paste Data
Top