Start a new topic

Problem with multiple sliders on one page.

Hello everyoneI would like to learn how to create multiple sliders

in a page to control several led, please in a simple way since I am

new in this programming and I want to learn.

You want to learn how, but I don't see you making any effort

Asking everyone how to do it for you is not how to learn

So I see you already have the CompSlider HMI and ino

Start with that as an example - run them

When you observe and understand the one slider

then work with 5.

To control several leds is NOT a nextion problem

- this you ask in Arduino forum.

You must begin to read, and then try small steps

Build on successes and read some more.

For the Nextion Side of this equation

Start a new HMI

click the Slider component 5 times

align them so that they do not overlap each other


Click on each and in their touch release events

check the Send Component ID


Save your project. and compile to build your TFT file

Upload your TFT to your Nextion device.

Read the Nextion Instruction Set, particular attention to the Nextion Return Codes

0x65 is the touch return codes.  This will let your MCU know when the use has released the slider.

0X65 Touch event return data

  • 0X65+Page ID+Component ID+TouchEvent+End
  • Return this data when the touch event created by the user is pressed.
  • Definition of TouchEvent: Press Event 0x01, Release Event 0X00)
  • Instance: 0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF
  • Meaning: Page 0, Button 2, Press

Then pay attention to Nextion Retun Data code 0x71.  This is how you will get your slider value when the slider has been released and you request the slider position from within your procedure. 

0X71 Numeric variable data returns
  • 0X71+variable binary data(4 bytes little endian mode, low in front)+End
  • When the variable obtained by get command is value, this data returns.
  • Instance:0X71 0X66 0X00 0X00 0X00 0XFF 0XFF 0XFF
  • Meaning:return value data:102

Little Endian is calculated by taking the four bytes
   buf[01] *1 + buf[02] *256 + buf[03] * 65536 + buf[04] * 16777126
Using the example above
   0X71 0X66 0X00 0X00 0X00 0XFF 0XFF 0XFF 

You will need to issue a get command to retrieve the slider value. 
See the Instruction Set section 2.6 for the get command explaination
You will be sending get h0.valÿÿÿ when you need slider h0's value and likewise
you need to send get h2.valÿÿÿ for slider h2, and h4.valÿÿÿ for slider h4.
Pay Attention to the three times mentioned "All commands are terminated with 0xFF 0xFF 0xFF

So when your MCU receives
0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF -- slider h0 has been released
Your MCU should send
get h0.valÿÿÿ  - requesting h0's value
You should wait in this routine for your answer to come back
0x71 0x64 0x00 0x00 0x00 0xFF 0xFF 0xFF
This you use your knowledge of little endian to arrive at h0 was at 100.
What you have your MCU do with this is up to you.

The same scenario will occur with each of the other 4 sliders.

Login or Signup to post a comment