Shop OBEX P1 Docs P2 Docs Learn Events
Do a calculation from serial data — Parallax Forums

Do a calculation from serial data

dakota77dakota77 Posts: 23
edited 2006-01-06 10:41 in BASIC Stamp

Hello,
From a Pocket Pc connected to BS2p I send the string "40A"

In the Basic Stamp I'd like to retrieve the value 40 and store it in variable x
Then do a calculation on x: y=x * 2

So I want to get the number 80.

In the program below :
The DEBUG 1) displays 40 (DEC x)
The DEBUG 2) displays P (ASCII code 80 = P)
How can I retrieve 40 as a number and then do operation on it ?
Thanks for your help.

main:
SERIN 7,16624,[noparse][[/noparse]DEC x]
IF x>0 THEN rel2
GOTO main

rel2:
DEBUG "1) DEC x = ",DEC x,CR
y=x*2
DEBUG "2) y = ",y
GOTO main

In the BS manual it's written :

"DEC tells SERIN to convert incoming text representing decimal numbers into true-decimal form and store the result in serdata. Afterwards, the program can perform any numeric operation on the number just like any other number."

Comments

Sign In or Register to comment.