In the sketch 4.1 – Input Keypad – Basic Locker is a mistake.
When using a external LED the state of the switch is not correctly adapted after giving the correct key. When the LED is ON, the switch is in the OFF state.
Here is the corrected part:
// Create a toggle switch (toggle_switch)
lv_obj_t * toggle_switch = lv_switch_create(lv_screen_active());
lv_obj_add_event_cb(toggle_switch, toggle_switch_event_handler, LV_EVENT_ALL, NULL);
lv_obj_add_flag(toggle_switch, LV_OBJ_FLAG_EVENT_BUBBLE);
// If the LED is on, turns the toggle switch on (checked)
//if(!digitalRead(CYD_LED_BLUE))
if(digitalRead(CYD_LED_BLUE))
{
lv_obj_add_state(toggle_switch, LV_STATE_CHECKED);
}
lv_obj_align(toggle_switch, LV_ALIGN_CENTER, 0, 0);
I had to change the !digitalRead(…) into the digalread(…) and everything worked.
Hi.
we explain previously in the ebook that the CYD LEDs work with inverted logic.
and if you’re using a separate ESP32 with a display and an external circuit, you need to change the code to the “regular” logic.
But, thanks for letting us know. I’ll add some notes about that issue next to the projects where it applies
Let me know if you need further help.
Regards.
Sara
Hello Sara,
I know that the external LEDs use inverted logic. You have also noted this in some places in the code and given the corresponding replacement codes. Only at this point in the programme there was no indication. I came across it when I re-entered the code and the LED was on, but the switch was OFF.
Regards.
Rudolf