Do a calculation from serial data
dakota77
Posts: 23
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
DEBUG "2) y = ",y
to read
DEBUG ")2 y = " dec y
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Yes the HX4700 has a serial port.
Mario