parsing a simple integer on serial
JazzD
Posts: 13
this is probably very simple again but i did not manage to get it working properly:
I have an atmega sending me ADC values every ~300ms. I'm using the FullDuplexSerial object to receive the data:
the string is constructed like this:
"$VAL%d\n",adcvalue
so the full 10bit output would look like:
$VAL1023(newline)
i would like to receive the data, parse the integer and store the integer in a variable, then do some calculations with the integer (this ADC is used to get a temperature value from an NTC resistor!).
whats a good way of doing this is in spin? thank you [noparse]:)[/noparse]
I have an atmega sending me ADC values every ~300ms. I'm using the FullDuplexSerial object to receive the data:
the string is constructed like this:
"$VAL%d\n",adcvalue
so the full 10bit output would look like:
$VAL1023(newline)
i would like to receive the data, parse the integer and store the integer in a variable, then do some calculations with the integer (this ADC is used to get a temperature value from an NTC resistor!).
whats a good way of doing this is in spin? thank you [noparse]:)[/noparse]
Comments
Cheers!
Paul Rowntree
It will return a -1 if the "$" is followed by an invalid value (not followed by "VAL" or
no digits following the "VAL") or it will return the numeric value following the "$VAL".
There's no checking for overflow of the 32-bit result. Any non-digit will terminate
the numeric portion of the value.
Post Edited (Mike Green) : 1/10/2009 7:52:35 PM GMT
PUB start | i
text.start(16)
serial2.start(12,11,0,4800)
i:= 10
repeat
i := parseData
text.setpos(10,5)
text.dec(i)
all it prints out now is -405? Whats wrong?
Plus, please use the code paste button to preserve indenting ... you can check if it looks right with previews.
Cheers!
Paul Rowntree
Cheers!
Paul Rowntree