Browse Source

kitchen_pilot_wire_control.ino: make code more readable

master
Richard Genoud 5 years ago
parent
commit
97f8e7b52e
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino

+ 12
- 4
soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino View File

@ -19,21 +19,29 @@ EspMQTTClient client(
const int heating_pin = 14;
#define heater_on(pin) do {\
digitalWrite(pin, LOW); \
} while(0)
#define heater_off(pin) do {\
digitalWrite(pin, HIGH); \
} while(0)
void message_callback(const String &message)
{
Serial.println(message);
if (message == "off") {
digitalWrite(heating_pin, HIGH);
heater_off(heating_pin);
}
if (message == "on") {
digitalWrite(heating_pin, LOW);
heater_on(heating_pin);
}
}
void setup()
{
pinMode(heating_pin, OUTPUT);
digitalWrite(heating_pin, HIGH); // by default output the voltage that switches off the heater
heater_off(heating_pin);
Serial.begin(115200);
@ -56,6 +64,6 @@ void loop()
client.loop();
if (!client.isConnected()) {
// if something wrong happens, switch off the heater
digitalWrite(heating_pin, HIGH);
heater_off(heating_pin);
}
}

Loading…
Cancel
Save