Page 1 of 1

Two switches in one node

Posted: Tue Dec 14, 2021 11:44 pm
by lucasdalmarco
I'm new to ESP-IDF would like to know how to add two keys on a single node, if anyone can share the files it would be a great help.

Re: Two switches in one node

Posted: Wed Dec 15, 2021 5:26 pm
by ESP_Piyush
Hello,

If you want to create a single device with 2 controlled GPIOs, please refer to the GPIO Example

If you want to create 2 virtual switch devices in a single node, please refer to the Multi Device Example. The multi device example has 1 switch, 1 fan, 1 light and 1 temperature sensor on the same node. You can use similar logic to have 2 switches.

If you want help with configuring 2 buttons to control 2 switches, you can use the below snippet for reference, which is similar to what we have in the example here.

Code: Select all

    button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
    if (btn_handle) {
        /* Register a callback for a button tap (short press) event */
        iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
    }

Re: Two switches in one node

Posted: Wed Dec 15, 2021 8:28 pm
by lucasdalmarco
Reading a thread I found an example with 4 switch, now I know the changes I need to make to get what I need.Thanks

Re: Two switches in one node

Posted: Sat Feb 26, 2022 5:19 am
by d9lan_
lucasdalmarco wrote:
Wed Dec 15, 2021 8:28 pm
Reading a thread I found an example with 4 switch, now I know the changes I need to make to get what I need.Thanks
Hi Lucas, I am having this problem, do you mind sharing the solution or posting/sending me a link of that thread with the 4 switches? Thanks