How to use button to activate a function

Hi everyone,

Working through how to use SLS.
I’m using SLS 1.2.0 with ESP32, TFT screen and Arduino IDE (MAC)

I’d like to learn how to assign a button action to call a function.
As a first step, how to toggle a LED on/off.

As an example of a simple button & blink function:

void loop() {
  last_button_state = button_state;      // save the last state
  button_state = digitalRead(BUTTON_PIN); // read new state

  if (last_button_state == HIGH && button_state == LOW) {
    Serial.println("The button is pressed");

    // toggle state of LED
    led_state = !led_state;

    // control LED arccoding to the toggled state
    digitalWrite(LED_PIN, led_state);
  }
}

Thanks for any guidance!

There is a YouTube tutorial about this.

Set the events of a button. Here are the specs you need to fill in

Name: as you like
Tigger: CLICKED
Action: CALL FUNCTION

Then press ADD (green button)

And fill in:
Function name: as you like

Hello, thank you guys for the post, someone, could please show an complete example in how to press a button in the interface and call a function in the code ? to turn on a LED for example, i’m a very begginer :(.

Do you mean in SLS or on real HW?

Real hardware, i’m using an esp32.

With screen or just some devkit with onboard LED?

With a screen, controller ili9341, touch xpt2046, i’m able to use the touch, and to call a function, but I dont know, for example, how to touch a button in the screen and turn on a GPIO, or how to touch a phisical button and change a state in the screen.

Try this :slight_smile: Simple_button.zip (12.3 KB)

Inside is SLS project and exported files with Arduino sketch. I hope it helps.

Than you very much for your help, I will open the files, I do eletronics design, If I could help in something let me know !! :grinning: