Advertisement
hidromotic

Agustín Senen Gonzalez

Mar 17th, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.46 KB | Source Code | 0 0
  1. //Agustín Senen Gonzalez
  2.  
  3. #define PIN_BOMBA 14
  4. #define CONFIG_BOMBA                pinMode(PIN_BOMBA, OUTPUT)
  5. #define EncenderBomba digitalWrite(PIN_BOMBA, HIGH)
  6. #define ApagarBomba digitalWrite(PIN_BOMBA, LOW)
  7.  
  8.  
  9. #define PIN_TQ_VACIO 9
  10. #define CONFIG_TQ_VACIO             pinMode(PIN_TQ_VACIO, INPUT)
  11. #define TanqueVacio digitalRead(PIN_TQ_VACIO)
  12.  
  13. #define PIN_TQ_LLENO 8
  14. #define CONFIG_TQ_LLENO             pinMode(PIN_TQ_LLENO, INPUT)
  15. #define TanqueLleno digitalRead(PIN_TQ_LLENO)
  16.  
  17. #define PIN_CISTERNA_VACIA 10
  18. #define CONFIG_CISTERNA_VACIA       pinMode(PIN_CISTERNA_VACIA, INPUT)
  19. #define CisternaVacia digitalRead(PIN_CISTERNA_VACIA)
  20.  
  21. #define PIN_FORZAR_LLENADO 11
  22. #define CONFIG_FORZAR_LLENADO       pinMode(PIN_FORZAR_LLENADO, INPUT)
  23. #define ForzarLlenado digitalRead(PIN_FORZAR_LLENADO)
  24.  
  25. #define PIN_LED_TEST 13
  26. #define CONFIG_LED_TEST             pinMode(PIN_LED_TEST, OUTPUT)
  27. #define EncenderLed digitalWrite(PIN_LED_TEST, HIGH)
  28. #define ApagarLed digitalWrite(PIN_LED_TEST, LOW)
  29.  
  30. #define TApagado 5000
  31. #define TEncendido 50
  32. #define TLlenado 5000
  33.  
  34. bool modoAutomatico = true;
  35. bool bombaEncendida = false;
  36. unsigned long tiempoInicioBomba = 0;
  37.  
  38. void setup() {
  39.     CONFIG_BOMBA;
  40.     CONFIG_TQ_LLENO;
  41.     CONFIG_TQ_VACIO;
  42.     CONFIG_CISTERNA_VACIA;
  43.     CONFIG_FORZAR_LLENADO;
  44.     CONFIG_LED_TEST;
  45.     Serial.begin(9600);
  46.     Serial.println("Nombre: Agustin");
  47.     Serial.println("Apellido: Senen Gonzalez");
  48. }
  49.  
  50. void loop()
  51. {
  52.     LedTest();
  53.     CtrlEncendido();
  54.     CtrlApagado();
  55.     rxSerie();
  56. }
  57.  
  58. void CtrlEncendido() {
  59.     bool tanqueVacio = TanqueVacio;
  60.     bool cisternaVacia = CisternaVacia;
  61.     bool forzarLlenado = ForzarLlenado;
  62.    
  63.     if ((modoAutomatico && tanqueVacio && !cisternaVacia) || forzarLlenado) {
  64.         bombaEncendida = true;
  65.         tiempoInicioBomba = millis();
  66.         txSerie("Inició el Llenado");
  67.     }
  68.  
  69.     if (bombaEncendida) {
  70.         EncenderBomba;
  71.     } else {
  72.         ApagarBomba;
  73.     }
  74. }
  75.  
  76. void CtrlApagado() {
  77.     if (TanqueLleno || CisternaVacia || (millis() - tiempoInicioBomba > TLlenado)) {
  78.         if (bombaEncendida) {
  79.             bombaEncendida = false;
  80.             ApagarBomba;
  81.             unsigned long tiempoLlenado = (millis() - tiempoInicioBomba) / 1000;
  82.             txSerie("Finalizó el llenado. Tardó " + String(tiempoLlenado) + " segundos en llenarlo.");
  83.         }
  84.         if (millis() - tiempoInicioBomba > TLlenado) {
  85.             modoAutomatico = false;
  86.             txSerie("Tiempo de seguridad alcanzado. Pasando a modo MANUAL.");
  87.         }
  88.     }
  89. }
  90.  
  91. void rxSerie() {
  92.     if (Serial.available()) {
  93.         char comando = Serial.read();
  94.         if (comando == 'A' || comando == 'a') {
  95.             modoAutomatico = true;
  96.             txSerie("Modo AUTOMÁTICO activado.");
  97.         } else if (comando == 'M' || comando == 'm') {
  98.             modoAutomatico = false;
  99.             txSerie("Modo MANUAL activado.");
  100.         } else if (comando == 'X' || comando == 'x') {
  101.             bombaEncendida = true;
  102.             tiempoInicioBomba = millis();
  103.         }
  104.     }
  105. }
  106. void txSerie(String mensaje) {
  107.     Serial.println(mensaje);
  108. }
  109.  
  110. void LedTest() {
  111.     static unsigned long millis_ant = 0;
  112.     static bool estado_led = false;
  113.     static int ms_espera = TApagado;
  114.  
  115.     if (millis() - millis_ant < ms_espera) return;
  116.     millis_ant = millis();
  117.  
  118.     estado_led = !estado_led;
  119.     digitalWrite(PIN_LED_TEST, estado_led);
  120.     ms_espera = estado_led ? TEncendido : TApagado;
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement