Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Example using Internal Pull-Ups for Arduino or Energia (TI Launchpad)
- ** code used in AddOhms Video Tutorial #15: Pull-Ups and Buttons
- ** More information, schematic, and tutorial visit: http://www.addohms.com/ep15
- **
- ** Public Domain Code by James Lewis, @baldengineer
- */
- const int buttonPin = P1_6;
- const int ledPin = P6_0;
- bool buttonState = 0;
- void setup()
- {
- pinMode(ledPin, OUTPUT);
- // added for debug, this will only work on Energia!
- pinMode(GREEN_LED, OUTPUT);
- pinMode(buttonPin, INPUT_PULLUP);
- Serial.begin(9600);
- }
- void loop()
- {
- // this code does not do any de-bounce
- buttonState = digitalRead(buttonPin);
- if (buttonState) {
- digitalWrite(ledPin, HIGH);
- // Again, Energia only
- digitalWrite(GREEN_LED, HIGH);
- Serial.println("High");
- } else {
- digitalWrite(ledPin, LOW);
- // Again, Energia only
- digitalWrite(GREEN_LED, LOW);
- Serial.println("Low");
- }
- delay(100); // reduces the serial.prints to something reasonable.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement