split a SERIN string in to two varibles?
Allex
Posts: 1
Hi all!
iam new to the BasicStamp and need some help whit this.
how can i split a incomming string from the serin command? this is my incomming "15#1100" i have used # as separator.
i whant to put 15 in VAR Servo and the value after # in to VAR ServoP.
BS2:
counter VAR Byte
Servo VAR Word
ServoP VAR Word
PAUSE 1000
Main:
SERIN 16, 16572,15,timeout,[Servo , ServoP]
timeout:
IF Servo ="1" THEN
Servo = 0
GOTO CENTER
ENDIF
GOTO Main
Servo:
FOR counter = 1 TO 50
PULSOUT Servo, ServoP
PAUSE 20
NEXT
GOTO Main
RETURN
_____________
//Alex
iam new to the BasicStamp and need some help whit this.
how can i split a incomming string from the serin command? this is my incomming "15#1100" i have used # as separator.
i whant to put 15 in VAR Servo and the value after # in to VAR ServoP.
BS2:
counter VAR Byte
Servo VAR Word
ServoP VAR Word
PAUSE 1000
Main:
SERIN 16, 16572,15,timeout,[Servo , ServoP]
timeout:
IF Servo ="1" THEN
Servo = 0
GOTO CENTER
ENDIF
GOTO Main
Servo:
FOR counter = 1 TO 50
PULSOUT Servo, ServoP
PAUSE 20
NEXT
GOTO Main
RETURN
_____________
//Alex
Comments
You should be able to grab the first number, skip the # and then grab the next number.
Take note of how the data is interpreted so as not to confuse the ASCII character for a number with the actual value of the number.
You don't mention whether you've actually got data arriving at the Stamp. I usually set up a very short loop with only the SERIN command and an LED which gets triggered if the SERIN actually sees some characters.