Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Button
- Turns on and off a light emitting diode(LED)
- connected to digital pin 13, when pressing a
- pushbutton attached to pin 2.
- The circuit:
- * LED attached from pin 13 to ground
- * pushbutton attached to pin 2 from +5V
- * 10K resistor attached to pin 2 from ground
- * Note: on most Arduinos there is already an LED
- on the board attached to pin 13.
- created 2005 by DojoDave <http://www.0j0.org>
- modified 30 Aug 2011 by Tom Igoe
- This example code is in the public domain.
- http://www.arduino.cc/en/Tutorial/Button
- */
- #define BUTTON_PIN 2
- #define LED_PIN 13
- int buttonState = 0;
- short pressCount = 0;
- void setup()
- {
- pinMode(BUTTON_PIN, INPUT);
- pinMode(LED_PIN, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- // read the state of the pushbutton value
- buttonState = digitalRead(BUTTON_PIN);
- // check if pushbutton is pressed. if it is, the
- // buttonState is HIGH
- if (buttonState == HIGH) {
- // turn LED on
- pressCount++;
- Serial.print("pressCount: ");
- Serial.println(pressCount);
- }
- if(pressCount == 3) {
- Serial.println("Blinkin LED");
- pressCount = 0;
- digitalWrite(LED_PIN, HIGH);
- delay(20);
- digitalWrite(LED_PIN, LOW);
- }
- delay(10); // Delay a little bit to improve simulation performance
- }
Add Comment
Please, Sign In to add comment