Line Graph, math problem...


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    41

    Default Line Graph, math problem...

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by ScaleRobotics; - 5th May 2009 at 21:52.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Feb 2009
    Posts
    41


    Did you find this post helpful? Yes | No

    Default :)

    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

Similar Threads

  1. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  4. Math Formula / Variable Problem! Help!
    By bwarp in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th February 2006, 07:59
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts