Browse Source

kitchen_pilot_wire_control.ino: add an hearbeat led

master
Richard Genoud 5 years ago
parent
commit
992d12dd09
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino

+ 16
- 0
soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino View File

@ -16,6 +16,11 @@ EspMQTTClient client(
);
const int heating_pin = 14;
const int led_pin = 2;
#define led_on(state) do {\
digitalWrite(led_pin, (state) ? LOW : HIGH); \
} while (0)
#define heater_on(pin) do {\
digitalWrite(pin, LOW); \
@ -58,6 +63,7 @@ void shutdown_heater(void *dummy)
void setup()
{
pinMode(heating_pin, OUTPUT);
pinMode(led_pin, OUTPUT);
heater_off(heating_pin);
Serial.begin(115200);
@ -80,9 +86,19 @@ void onConnectionEstablished()
void loop()
{
static unsigned int counter;
static bool led_state = false;
client.loop();
if (!client.isConnected()) {
// if something wrong happens, switch off the heater
heater_off(heating_pin);
}
// blink ESP blue led to show that we are alive
if (((led_state) && (counter % 1000 == 0)) || (!led_state && (counter % 30000 == 0))) {
led_state = !led_state;
led_on(led_state);
}
counter++;
}

Loading…
Cancel
Save