SHARE
TWEET

hiiiiiii

a guest Nov 14th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3.  * Attempting a Stoplight Program
  4.  */
  5.  
  6. const int buttonPin = 12;
  7. const int greenLED = 2;
  8. const int yellowLED = 3;
  9. const int redLED= 4;
  10.  
  11. bool buttonPressed = false;
  12.  
  13.  
  14. // the setup function runs once when you press reset or power the board
  15.  
  16. void setup() {
  17.   // initialize digital pin LED_BUILTIN as an output.
  18.   pinMode(yellowLED, OUTPUT);
  19.   pinMode(greenLED, OUTPUT);
  20.   pinMode(redLED, OUTPUT);
  21.   pinMode(buttonPin, INPUT);  
  22.   //Space
  23.   Serial.begin(9600);
  24. }
  25.  
  26. // the loop function runs over and over again forever
  27. void loop() {
  28.     Serial.println(digitalRead(buttonPin));
  29.     buttonPressed = digitalRead(buttonPin);
  30.     if(digitalRead(buttonPin)){
  31.       buttonPressed = true;
  32.       lightChange();
  33.     }else{if(!buttonPressed){
  34.       lightGo();
  35.     }
  36.     }
  37.  
  38.   //Step();
  39. }
  40. void lightStop(){
  41.     digitalWrite(greenLED, LOW);  
  42.     digitalWrite(yellowLED,LOW);
  43.     digitalWrite(redLED,HIGH);
  44. }
  45.  
  46. void lightGo(){
  47.       digitalWrite(greenLED, HIGH);
  48.       digitalWrite(yellowLED,LOW);
  49.       digitalWrite(redLED,LOW);
  50. }
  51. void lightYield(){
  52.       digitalWrite(greenLED, LOW);  
  53.       digitalWrite(yellowLED,HIGH);
  54.       digitalWrite(redLED,LOW);  
  55. }
  56. void lightChange(){
  57.       buttonPressed = false;
  58.       lightGo();
  59.       delay(2000);                      
  60.       lightYield();
  61.       delay(2000);                    
  62.       lightStop();
  63.       delay(2000);
  64.  
  65. }
  66.  
  67.  
  68. /*void Step() {
  69.   int newi1 = i2;
  70.   out = i1 + i2;
  71.   i1= i2;
  72.   i2 = out;
  73.   Serial.println(out);
  74.   if( out >= 100) {
  75.     i1 = 0;
  76.     i2 = 1;
  77.     out = 1;
  78.   }
  79. }
  80. */
RAW Paste Data
Top