static uint8_t gpio_relay1 = 2;
static uint8_t gpio_switch1 = 32;
bool switch_state_ch1 = false;
struct LightSwitch {
const uint8_t pin;
bool pressed;
bool old;
};
LightSwitch switch_ch1 = {gpio_switch1, false, false};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(switch_ch1.pin, INPUT_PULLUP);
pinMode(gpio_relay1, OUTPUT);
digitalWrite(gpio_relay1, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
switch_ch1.pressed = !digitalRead(switch_ch1.pin);
if(!switch_ch1.pressed && switch_ch1.old){
switch_state_ch1 = !switch_state_ch1;
Serial.println(switch_state_ch1);
}
switch_ch1.old = switch_ch1.pressed;
/* if (switch_ch1.pressed) {
Serial.printf("Switch 1 has been changed\n");
switch_ch1.pressed = false;
// Toggle switch 1 device state
switch_state_ch1 = !switch_state_ch1;
Serial.printf("Toggle State to %s.\n", switch_state_ch1 ? "true" : "false");
//if (my_switch1) {
//my_switch1->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1);
//}
(switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH);
}
else{
//if(!digitalRead(switch_ch1.pin)) pressBtn(&switch_ch1);
} */
}