Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Button Proofing

By: a guest on Feb 5th, 2013  |  syntax: C++  |  size: 2.17 KB  |  views: 183  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     /*
  2.  
  3.      Turns on an LED on for one second, then off for one second, repeatedly.
  4.  
  5.      This example code is in the public domain.
  6.     */
  7.                               //EXPLAINATION: we are making a window that opens and closes based on temp, humidity, rain, and windspeed
  8.                               //While we do not have the sensors
  9.     // Pin 13 has an LED connected on most Arduino boards.
  10.     // give it a name:
  11.     const int open = 12;
  12.     const int close = 13;
  13.     const int buttonPin = 2;
  14.     int incomingByte = 0;
  15.  
  16.     int buttonState = 0;
  17.  
  18.     // the setup routine runs once when you press reset:
  19.     void setup() {  
  20.      pinMode(open, OUTPUT);                   //button to provide user feedback that the window is closing
  21.      pinMode(close, OUTPUT);                  //button to provide user feedback that the window is closing
  22.      pinMode(buttonPin, INPUT);
  23.      }
  24.  
  25.     // the loop routine runs over and over again forever:
  26.     void loop() {
  27.  
  28.      buttonState = digitalRead(buttonPin);
  29.      int C = 0;                               //
  30.  
  31.     while (C == 0) {  
  32.      if (buttonState == HIGH) {
  33.        delay(500);                            //wait
  34.        if (buttonState == LOW){               //waits until button is released
  35.          digitalWrite(close, LOW);            //light that signals the window is closing is off
  36.          digitalWrite(open, HIGH);            //light that signals the window is opening is on
  37.          C = 1;                               //set C value to note that the window is closed
  38.        }
  39.        else{
  40.        }
  41.      }
  42.      else{
  43.      }
  44.     }
  45.  
  46.     while (C == 1) {                            //while the window is closed
  47.      if (buttonState == HIGH) {                //if the button is pressed
  48.         delay(500);                            //pause
  49.              if (buttonState == LOW){          //waits until button is released
  50.          digitalWrite(open, LOW);              //light that signals the window is closing is off
  51.          digitalWrite(close, HIGH);            //light that signals the window is opening is on
  52.          C = 0;
  53.        }
  54.        else{
  55.        }
  56.      }
  57.      else{
  58.      }
  59.     }
  60.      }