daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int
  2.   LED = 13,
  3.   BUTTON = 7;
  4.  
  5. int
  6.   val = 0,
  7.   oldval = 0,
  8.   state = 0;
  9.  
  10. void setup() {
  11.   pinMode(LED, OUTPUT);
  12.   pinMode(BUTTON, INPUT); //setea los pins, cual es el LED y cual el boton
  13. }
  14.  
  15. void loop() {
  16.   val = digitalRead(BUTTON); //devuelve 1 o 0, dependiendo de si se aprieta el boton o no
  17.  
  18.   if (val == HIGH && oldval == LOW) { //high = 1, low = 0
  19.     state = 1 - state;
  20.     delay(10);
  21.   }
  22.  
  23.   oldval = val;
  24.  
  25.   if (state == 1) digitalWrite(LED, HIGH); //prende la luz
  26.   else digitalWrite(LED, LOW); //la apaga
  27. }
RAW Paste Data
Top