PDA

View Full Version : Line Graph, math problem...



TerdRatchett
- 5th May 2009, 20:35
I am writing a custom graphing function for a GLCD display. I'm having some difficulty in the math to calculate which dot gets shown for a given input. My math leaves me with a decimal value, which are of little use without floating point math.

For example, lets say we have a scale that goes from 0-4800 and the Y is 8 bits x 6 pages, or 48 bits high. So each pixel is worth 100. If we receive data that is 2400, then we would want to turn on the 24th pixel. By dividing the input data by the total worth of a page (800 which is 8 pixels) I know which page my dot is going to be on. trouble is when I try to come up with a way to determine which pixel of that byte will be displayed, I get a decimal value. Any ideas?

TIA,
TR

ScaleRobotics
- 5th May 2009, 21:06
I think I don't quite understand the question. Your lcd can only show in decimal 1 through 48, so shouldn't decimal be ok to work with? If you are asking about how to average your remainder so you can display the right pixel, then you could do your divide by 100, for the pixel, then take your remainder. If your remainder > 49 then pixel = pixel + 1. This is saying that if your division returned 24.5 or higher, it would be displayed as pixel 25. This would smooth out your line graph a little bit.

Is that what you are getting at?

Or, if you are saying that you do have a decimal point (or a decimal after your whole number), then you can do something with it. Same as above, but if you have 245, then 245//10 will give your remainder. If remainder > 4 then pixel = pixel + 1

Added:
Ok, if you're asking how to figure out what page and pixel to display.......:
Say you want to display pixel 10 of the 48 pixels. 10/8 = 1 so it is on page 1 (of 0 to 7 pages). Now for the pixel of that page, you take the remainder 10//8 = 2. So it is pixel 2 on page 1 we need to display.

TerdRatchett
- 6th May 2009, 04:20
Dear scalerobotics,

I thank you very much for the excellent response. You answered my question with 245//10 as opposed to 245/10. I had noticed that in the book when I first read it months ago but forgot that you could extract the remainder as well in performing a division. That happens when you get to be my age :)

I'm about to give that a try, I suspect it will work great!

Thanks again!
TR