Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <Bounce.h>
  2.  
  3.  
  4. int  botonPin1=2;// pines donde se conectan los botones
  5. int  botonPin2=3;
  6. int  botonPin3=4;
  7. int  botonPin4=5;
  8.  
  9. int botonstadoAr=0;         // variables para el estado de boton
  10. int botonstadoab =0;
  11. int botonstadode=0;
  12. int botonstadoiz=0;
  13.  
  14.  
  15. Bounce arriba=Bounce(botonPin1,5);// utilizamos la libreria Bounce
  16. Bounce abajo=Bounce (botonPin2,5);
  17. Bounce izquierda=Bounce (botonPin3,5);
  18. Bounce derecha=Bounce (botonPin4,5);
  19.  
  20.  
  21. void setup() {
  22.                      
  23.   // coloca los botones en salida:
  24.  
  25.     pinMode(botonPin1, INPUT);
  26.     pinMode(botonPin2, INPUT);
  27.     pinMode(botonPin3, INPUT);
  28.     pinMode(botonPin4, INPUT);
  29.    
  30.     digitalWrite(botonPin1, HIGH);  
  31.    digitalWrite(botonPin2, HIGH);  
  32.    digitalWrite(botonPin3, HIGH);  
  33.    digitalWrite(botonPin4, HIGH);  
  34.  
  35. Serial.begin(9600);
  36. }
  37.  
  38. void loop(){
  39.  
  40.   arriba.update();
  41.   abajo.update();
  42.   derecha.update();
  43.   izquierda.update();
  44.  
  45.   int botonstadoAr=arriba.read(); // variables para el estado de boton
  46. int  botonstadoab =abajo.read();
  47. int botonstadode=derecha.read();
  48. int  botonstadoiz=izquierda.read();
  49.    
  50.  
  51.   // mira si el boton es precionado
  52.   // preguntamo si el boton esta LOW
  53.   if (botonstadoAr==LOW) {    
  54.     Serial.println(1,DEC);
  55.    
  56.    
  57.   }
  58.  
  59.   //boton2
  60.   if (botonstadoab == LOW ) {    
  61.    Serial.println(2,DEC);
  62.   }
  63.  
  64.  
  65.   //boton3
  66.   if (botonstadode == LOW ) {    
  67.        Serial.println(3,DEC);
  68.   }
  69.  
  70.  
  71.   //boton 4
  72.   if (botonstadoiz ==LOW ) {    
  73.    
  74.     Serial.println(4,DEC);
  75.   }
  76.  
  77.   delay (100);
  78.  
  79. }