Advertisement
hidromotic

PulsadorDomoticaCombinacion

Apr 14th, 2020
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. /*
  2.  * Pulsador de Domótica
  3.  */
  4. #define PIN_LED             13
  5. #define CONFIGURAR_LED      pinMode(PIN_LED, OUTPUT)
  6. #define ENCENDER_LED        digitalWrite(PIN_LED, HIGH)
  7. #define APAGAR_LED          digitalWrite(PIN_LED, LOW)
  8.  
  9. #define PIN_LUZ             11
  10. #define CONFIGURAR_LUZ      pinMode(PIN_LUZ, OUTPUT)
  11. #define ENCENDER_LUZ        digitalWrite(PIN_LUZ, HIGH)
  12. #define APAGAR_LUZ          digitalWrite(PIN_LUZ, LOW)
  13.  
  14. #define PIN_BOT1            7
  15. #define CONFIGURAR_BOT1     pinMode(PIN_BOT1, INPUT_PULLUP)
  16. #define BOT1_PRESIONADO     (digitalRead(PIN_BOT1)==LOW)
  17.  
  18. #define PIN_BOT2            5
  19. #define CONFIGURAR_BOT2     pinMode(PIN_BOT2, INPUT_PULLUP)
  20. #define BOT2_PRESIONADO     (digitalRead(PIN_BOT2)==LOW)
  21.  
  22. #define PIN_BOT3            3
  23. #define CONFIGURAR_BOT3     pinMode(PIN_BOT3, INPUT_PULLUP)
  24. #define BOT3_PRESIONADO     (digitalRead(PIN_BOT3)==LOW)
  25.  
  26. void setup()
  27.   {
  28.    //Salidas
  29.   CONFIGURAR_LED;
  30.   CONFIGURAR_BOT1;
  31.   CONFIGURAR_BOT2;
  32.   CONFIGURAR_BOT3;
  33.   //Entrada
  34.   CONFIGURAR_LUZ;
  35.   }
  36.  
  37. bool luz=0;
  38.  
  39. void loop()
  40.   {
  41.   SupervisaBotones();
  42.   ActualizaLuz();
  43.   LedTest();
  44.   }
  45.  
  46. void SupervisaBotones(void)
  47.   {
  48.   static bool bot1_presionado_ant=0;
  49.   static bool bot2_presionado_ant=0;
  50.   static bool bot3_presionado_ant=0;
  51.  
  52.   if(BOT1_PRESIONADO && !bot1_presionado_ant)    luz=!luz;
  53.   if(BOT2_PRESIONADO && !bot2_presionado_ant)    luz=!luz;
  54.   if(BOT3_PRESIONADO && !bot3_presionado_ant)    luz=!luz;
  55.  
  56.   bot1_presionado_ant=BOT1_PRESIONADO;
  57.   bot2_presionado_ant=BOT2_PRESIONADO;
  58.   bot3_presionado_ant=BOT3_PRESIONADO;
  59.   }
  60.  
  61. void ActualizaLuz(void)
  62.   {
  63.   if(luz) ENCENDER_LUZ;
  64.   else    APAGAR_LUZ;
  65.   }
  66.  
  67. void LedTest(void)
  68.   {
  69.   static bool encender_led=0;
  70.   static unsigned long millis_ant=0;
  71.  
  72.   if(millis()-millis_ant < 1000) return;
  73.   millis_ant=millis();
  74.  
  75.   //Invertir el estado del led
  76.   encender_led = !encender_led;
  77.  
  78.   if(encender_led)  ENCENDER_LED;
  79.   else              APAGAR_LED;
  80.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement