• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Error in 4.1 – Input Keypad – Basic Locker

Q&A Forum › Category: Questions › Error in 4.1 – Input Keypad – Basic Locker
0 Vote Up Vote Down
Rudolf Reiber asked 12 months ago

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.

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 12 months ago

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

0 Vote Up Vote Down
Rudolf Reiber answered 12 months ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 12 months ago

Thanks for pointing that out.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.