SHARE
TWEET

Code for AO #15: Pull-Ups

baldengineer Aug 9th, 2015 386 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Example using Internal Pull-Ups for Arduino or Energia (TI Launchpad)
  2. ** code used in AddOhms Video Tutorial #15: Pull-Ups and Buttons
  3. ** More information, schematic, and tutorial visit: http://www.addohms.com/ep15
  4. **
  5. ** Public Domain Code by James Lewis, @baldengineer
  6. */
  7.  
  8. const int buttonPin = P1_6;
  9. const int ledPin = P6_0;
  10.  
  11. bool buttonState = 0;
  12.  
  13. void setup()
  14. {
  15.   pinMode(ledPin, OUTPUT);
  16.  
  17.   // added for debug, this will only work on Energia!
  18.   pinMode(GREEN_LED, OUTPUT);
  19.  
  20.   pinMode(buttonPin, INPUT_PULLUP);
  21.   Serial.begin(9600);
  22. }
  23.  
  24. void loop()
  25. {
  26.   // this code does not do any de-bounce
  27.   buttonState = digitalRead(buttonPin);
  28.  
  29.   if (buttonState) {
  30.     digitalWrite(ledPin, HIGH);
  31.     // Again, Energia only
  32.     digitalWrite(GREEN_LED, HIGH);
  33.     Serial.println("High");
  34.   } else {
  35.     digitalWrite(ledPin, LOW);
  36.     // Again, Energia only
  37.     digitalWrite(GREEN_LED, LOW);
  38.     Serial.println("Low");
  39.   }
  40.   delay(100); // reduces the serial.prints to something reasonable.
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top