Aodai

Untitled

Oct 23rd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   Button
  3.   Turns on and off a light emitting diode(LED)
  4.   connected to digital  pin 13, when pressing a
  5.   pushbutton attached to pin 2.
  6.  
  7.    The circuit:
  8.   * LED attached from pin 13 to ground
  9.   * pushbutton attached to pin 2 from +5V
  10.   * 10K resistor attached to pin 2 from ground
  11.   * Note: on most Arduinos there is already an LED
  12.   on the board  attached to pin 13.
  13.  
  14.   created 2005  by DojoDave <http://www.0j0.org>
  15.  
  16.   modified 30 Aug 2011  by Tom Igoe
  17.  
  18.   This example code is in the public domain.
  19.   http://www.arduino.cc/en/Tutorial/Button
  20. */
  21.  
  22. #define BUTTON_PIN 2
  23. #define LED_PIN 13
  24.  
  25. int buttonState = 0;
  26. short pressCount = 0;
  27.  
  28. void setup()
  29. {
  30.   pinMode(BUTTON_PIN, INPUT);
  31.   pinMode(LED_PIN, OUTPUT);
  32.   Serial.begin(9600);
  33. }
  34.  
  35. void loop()
  36. {
  37.   // read the state of the pushbutton value
  38.   buttonState = digitalRead(BUTTON_PIN);
  39.   // check if pushbutton is pressed.  if it is, the
  40.   // buttonState is HIGH
  41.   if (buttonState == HIGH) {
  42.     // turn LED on
  43.     pressCount++;
  44.     Serial.print("pressCount: ");
  45.     Serial.println(pressCount);
  46.   }
  47.   if(pressCount == 3) {
  48.     Serial.println("Blinkin LED");
  49.     pressCount = 0;
  50.     digitalWrite(LED_PIN, HIGH);
  51.     delay(20);
  52.     digitalWrite(LED_PIN, LOW);
  53.   }
  54.   delay(10); // Delay a little bit to improve simulation performance
  55. }
Add Comment
Please, Sign In to add comment