Advertisement
patriotaSJ

Botón enciende led2

Apr 19th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. //http://cursoarduinomega.blogspot.com.ar/2015/04/boton-enciende-led.html
  2. int boton = 4;
  3. int led = 6;
  4.  
  5. void setup() {
  6.   pinMode(boton, INPUT);
  7.   pinMode(led, OUTPUT);
  8. }
  9.  
  10. int estado = 0;          //guarda el estado del botón
  11. int estadoAnterior = 0;  //guarda el estado anterior del botón
  12. int salida = 0;           // 0 = led pagado, 1 = led encendido
  13.  
  14. void loop() {
  15.   estado = digitalRead(boton);  //lee el estado del boton
  16.   if(( estado == HIGH ) && ( estadoAnterior == LOW )){
  17.     salida = 1 - salida;
  18.   }
  19.  
  20.   estadoAnterior = estado;
  21.    
  22.   if ( salida == 1 ){
  23.     digitalWrite(led, HIGH);
  24.   }
  25.   else{
  26.     digitalWrite(led, LOW);
  27.   }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement