Start a new topic

Waveform scale


I just got my Nextion display and I am trying to plot a value from my Arduinos analog input. I am using the ITEAD library.

Everything works fine and the value is plotted, but I cannot seem to find out how to set the scale for tha waveform? i.e. if I want to plot a value between 0 and 3000, and I set the grid to 50. I want 0 to be at the bottom of the waveform and 3000 to be at the top. If I send value 1500 I want that to be plotted in the middle.

How do I set this scale? Right now everything plots around the middle.

Every data point is a byte - range of 0 to 255.   3000 = 255, 0 = 0.

So sending a value in the center is going to be 127 (just below half) and 128 (just above half)

  val            x

-------   x   -------  =     x  =  val * 255 / 3000

3000         255

For the sake of  reducing it for easier Nextion integer math you would use

x  = val * 17 / 200

calculate for x  

where val is your number for from 0 to 3000 and

where x is the value need for the add or addt command.

Give that a shot and see it that will work.

Thanks for the clue! 

The thing I didin't know was that the scale is the same as the pixel-size of the waveform. i.e. if I have a waveform that is 200px x 160px (200 wide, 160 height), the X scale is 0-200 and the Y-scale is 0-160. Mapping this in Arduino is very simple with the map command :) 

Now everything works as expected!

Login or Signup to post a comment