I've read that several times and I am not clear what you are doing. Can you give me both the code on the scroll bar and the corresponding code on the Arduino please?
HMI_read_data[4]
Is 1 byte. You need 2 bytes for a range of 500 to 5000.
My heating controller has sliders to control the temperature setting with a range of 0 to 300. That gives me 30 degrees range in steps of 0.1 degree (yes, I know, I probably should be using 0 to 299). That means that the data sent from the sliders takes 2 bytes. The section of code that takes the slider values and updates the set temperature is this:
case 1:
zone[HMI_read_data[3]].settemp = (HMI_read_data[4] | HMI_read_data[5] << 8) * 0.1; //Note 1
zone[HMI_read_data[3]].flags_HMI |= HMI_text_settemp_update; //Note 2
break;
Note 1, this is the update for the temperature setting:
(HMI_read_data[4] | HMI_read_data[5] << 8)
Combines 2 bytes into one integer, which is the value of the slider setting. I think you need something similar.
Note 2, this is a flag to tell the rest of the program that there has been an update
Although not the cause of your problem, I suggest you don't use that range. I don't know which Nextion you are using, but the highest number of pixels in one direction is 800, so the maximum possible number of unique values from a slider is 800. Any more than that cannot be resolved on the display, so while you might get meaningful values with a slider with a range of 4500, there must, I presume, be gaps in the numbers.
While 500 to 5000 should work from a software point of view, my suggestion would be to use 0 to 4500 and add the 500 in on the Arduino.
In case you are interested, this is another way to combine 2 or more bytes into and integer, or split an integer into bytes, something like:
union {
struct {
uint8_t data_0;
uint8_t data_1;
}
uint16_t data;
}
If you write to data_0 and data_1 the two bytes will appear in data as a 16 bit int, if you write a 16 bit int to data then you can read the corresponding 2 byes from data_0 and data_1. You can of course expand this for larger ints and for floats.