Shop OBEX P1 Docs P2 Docs Learn Events
Scaling input and output — Parallax Forums

Scaling input and output

Eric REric R Posts: 225
edited 2008-04-05 13:29 in General Discussion
Wanted to get some ideas on this before I decided which way I was going to go.
I have a variable serial input that is ranging from 0-480 in counts·and a serial·output of 0-24 inches.
It would be best thought as a 0-480 count moving a actuator 0-24 inches. If my decimal input is roughly 240 then my actuator needs to be at roughtly 12 inches or simply decimal 12 serial out.
I wanted some degree of accuracy but do not want to kill the speed. My thoughts were dividing the 480 by 24 inches and setting up 24 if/then statements. This would give me accuracy to 1 inch. I would like better resolution but don't want to kill the scan time either.
What are your thoughts?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-04-05 04:29
    So, the input is an integer from 0 to 480 and the output is an integer from 0 to 24? If that is what you have try output = input / 20

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Eric REric R Posts: 225
    edited 2008-04-05 13:29
    Thanks and you are 100% correct. This will give 1" of resolution and will likely be about the best I can do without floating point math.
Sign In or Register to comment.