How to change the state of a button

Description

How to change the state of a button.

What MCU/Processor/Board and compiler are you using?

ESP32, WT32-SC01, SquareLine Studio + PlatformIO + Arduino Framework

What LVGL version are you using?

8.2.0

What do you want to achieve?

Change the state of a button.

What have you tried so far?

Tried the following functions, but none of them are accepted:

  • lv_btn_set_state
  • lv_obj_set_state

Code to reproduce

Could not find anything which worked.

Hi,

When you say set the state do you mean enable/disable it?

Regards

I think it is called CHECKED and RELEASED.
I can get the status using lv_obj_get_state.
But trying to change the state using lv_obj_set_state results in not declared in this scope.

What are you trying to achieve?

I have a button which can control a lamp through MQTT.
But this lamp can also be controlled by a different controller through MQTT.
So if the state of the lamp changes by a different controller, this should be reflected by the state of the button.

Can you share any code or screenshots?

It sounds like you need a switch instead of a button.

If I would use a switch, how do I change its state?

Have you read the docs?

https://docs.lvgl.io/latest/en/html/widgets/switch.html

I think function “lv_obj_add_state(obj*,state)” would work ,state can be any thing like LV_STATE_PRESSED

you can refer Link-Objects — LVGL documentation

This works!
I can set and reset the buttons state with lv_obj_add_state() and lv_obj_clear_state(), using LV_STATE_CHECKED.

Thanks!