#include <ESP32Servo.h>
#define valvePin 22
#define open true
#define closed false
Servo radiatorValve;
boolean valveState = open;
void setup() {
radiatorValve.attach(valvePin);
}
void loop() {
checkForUpdate();
/*valve can either be open (90 degrees)
or closed (0 degrees)*/
radiatorValve.write(valveState ? 90 : 0);
delay(500);
}
void toggleValve(){
valveState = !valveState;
}
void checkForUpdate(){
/*connect to IoT hub
check if value has updated
if has updated then toggle the valve to keep in line*/
toggleValve();
/*not actually doing an connections for this example
so just doing the toggleValve every time to simulate
the system telling it to open and close valve*/
}