diff --git a/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino index 991830e..bfe4ef5 100644 --- a/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino +++ b/soft/kitchen/kitchen_pilot_wire_control/kitchen_pilot_wire_control.ino @@ -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); } }