Advertisement
Guest User

blabla

a guest
Mar 18th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // constants won't change. They're used here to set pin numbers:
  2. const int buttonPin = 7; // the number of the pushbutton pin
  3. const int ledPin = 3; // the number of the LED pin
  4.  
  5. // variables will change:
  6. int buttonState = 0; // variable for reading the pushbutton status
  7. int anterior = 0;
  8. int ledState = 0;
  9.  
  10. void setup() {
  11. // initialize the LED pin as an output:
  12. pinMode(ledPin, OUTPUT);
  13. // initialize the pushbutton pin as an input:
  14. pinMode(buttonPin, INPUT);
  15. }
  16.  
  17. void loop() {
  18. // read the state of the pushbutton value:
  19. buttonState = digitalRead(buttonPin);
  20.  
  21. // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  22. if ((buttonState == HIGH) && (anterior == LOW)) {
  23. // HAY PULSACION
  24.  
  25. if (ledState == HIGH) {
  26. // turn LED off:
  27. digitalWrite(ledPin, LOW);
  28. ledState = LOW;
  29. }
  30. else {
  31. // turn LED on:
  32. digitalWrite(ledPin, HIGH);
  33. ledState = HIGH;
  34. }
  35. }
  36. anterior = buttonState;
  37.  
  38. delay(100);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement