Shop OBEX P1 Docs P2 Docs Learn Events
converting string data to a numeric value — Parallax Forums

converting string data to a numeric value

DgswanerDgswaner Posts: 795
edited 2008-04-21 16:42 in Propeller 1
I'm trying to receive a value from 0-255, convert it to a number between 500-2300 and then use that value to drive the servos.
I know the communication is working, but what I believe to be happening is that it's reading X as a string and not a numeric value, I can't find anything in the manual to convert this to the value. I've used something like VAL(X) in other languages.

the 0-255 is being generated by a HTML page (pink) and needs to be a integer. Here is my code.

PUB Main
    repeat
      x := XB.RX   ' receives a byte of data
      comm.dec(x)   'sends byte to pc 
           
      SERVO.Set(TiltServo,(X * 7) + 500) '500 - 2300
      SERVO.Set(PanServo,(X * 7) + 500) '  500 - 2300
      waitcnt (cnt+140_000)




Is there a way around this? any help would be appreciated.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-04-18 07:53
    Yep, you can use the Numbers object to do this. I think that there is a demo. It probably looks a bit daunting but most of that it just a whole heap of constants to make things easy.
  • DgswanerDgswaner Posts: 795
    edited 2008-04-18 11:48
    thanks I'll check it out.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • DgswanerDgswaner Posts: 795
    edited 2008-04-21 16:19
    I've tried for a few days to make since of the Numbers object. Does anyone have example code or some insite into using this object. I would appreciate any help. it looks like it will do what I need it to but I can't get the syntax right.

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • jazzedjazzed Posts: 11,803
    edited 2008-04-21 16:42
    Peter Verkaik's Format.spin object has itoa and atoi functions.
    http://obex.parallax.com/objects/230/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
Sign In or Register to comment.