Convert ASCII String into Integer
SailerMan
Posts: 337
I am using a Maxbotic Sonar the I have Choices of Output Serial, PWM or Analog. I used the PWM and now I'm attemping serial.
The data is Sent "R065\r"· 065 is the range in Inches.
I am reading the 065 into a short array and then Adding the Elements as so..
Repeat Index From 0 to 2
·· R[noparse][[/noparse]Index]=Serial.RX-48··· '<
FORGOT TO SUBTRACT 48
Range:=R[noparse][[/noparse]0]*100+R[noparse][[/noparse]1]*10+R[noparse][[/noparse]2]
It works but I'm wondering if there Is·a better way to handle this?
Thanks,
Eric
Post Edited (SailerMan) : 11/10/2006 5:19:39 PM GMT
The data is Sent "R065\r"· 065 is the range in Inches.
I am reading the 065 into a short array and then Adding the Elements as so..
Repeat Index From 0 to 2
·· R[noparse][[/noparse]Index]=Serial.RX-48··· '<
FORGOT TO SUBTRACT 48
Range:=R[noparse][[/noparse]0]*100+R[noparse][[/noparse]1]*10+R[noparse][[/noparse]2]
It works but I'm wondering if there Is·a better way to handle this?
Thanks,
Eric
Post Edited (SailerMan) : 11/10/2006 5:19:39 PM GMT
Comments
This is closer to my actual code
I like your approach much better plus it helps me think outside of my little obscure box.
If I understand your code it looks like a SHL·for Decimal.. Sheesh why didn't I think of that...
Thanks for your help,
Eric
Post Edited (SailerMan) : 11/10/2006 5:26:40 PM GMT