Start a new topic

How to make a function in Nextion for dim increase and decrease

Hello guys.


I am trying to make a slider to control DIM light of nextion hmi.


I started by making a simple if (0<h0.val<10) dim=10 ,etc to other values.


Looks like I cannot make the 0<h0.val<10 in nextion editor.


Any ideas other than making an if for every value?


thanks


Nextion Instruction Set defines dim and dims as the value for backlight in percent %

dim=50    // 50% backlight

dim=40    // 40% backlight

if you were to use the version of the dims command

dims=50   // set backlight to 50% and save as next power on default value.


One could make a page with a slider.


In the page PostInitialization Event set h0.val equal to dim and initialize the slider to current backlight

h0.val=dim

In the slider Touch Move Event set the backlight to the position of the slider

dim=h0.val

In the slide Touch Release Event transfer this value to the default power on default

dims=h0.val





HMI
(1.99 KB)

2 people like this

Dear Patrick,


It works pretty well, thanks a lot. Now I want to make it available on all pages (I have 3 pages) and with the same value as in the page before. Because right now each time I go to a certain page the slider is not at the same value as the previous page.


Any idea?


Thanks

Filipe

As you are changing pages from one to another the backlight value has changed?



Your page slider needs to be initialized in the page in which the slider is present, but you shouldn't need to have a "setting" control any other place but in a "setting" section.  Since the slider was using dims on touch release it should have been saved both as current setting and as the default for power on. 


I would check that other code isn't trying to alter the dim and dims settings causing a conflict


All page variables are generally local (dim/dims being a system wide global).  a slider of h0 on page 1 is different than the slider of h0 on page 2.  You have to think that as pages change, the mcu is going to flush all the local components and load HMI default user-defined values on entering a new page.



Perhaps the h0.val=dim should have been placed in the PreInitialize and not PostInitialize

Works pretty fine. Thanks Patrick

Thanks Mr. Martin .

Login or Signup to post a comment