PINK Netburner Ethernet Card and Variable Setting
bshack
Posts: 13
I am trying to control the blink rate of a LED based on information submitted online via the PINK Netburner Card. I have the below code to pull the variable NB0R01 from the PINK network card but I am having trouble using the info in the rest of my pbasic code. runtime = NBVAR does not work right.. for instance if NB0R01 equaled 500 my LED would still only pause like the variable was 20. Any ideas on how I can have the NB0R01 value be correctly set as the runtime variable to correctly pause?
----
' PINK_02.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
runtime VAR Word
NBVAR VAR Byte
SEROUT 8,396,[noparse][[/noparse]"!NB0R01"]
SERIN 7,396,[noparse][[/noparse]STR NBVAR\16\CLS]
DEBUG STR NBVAR
runtime = NBVAR
DO
HIGH 14
PAUSE runtime
LOW 14
PAUSE runtime
LOOP
----
' PINK_02.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
runtime VAR Word
NBVAR VAR Byte
SEROUT 8,396,[noparse][[/noparse]"!NB0R01"]
SERIN 7,396,[noparse][[/noparse]STR NBVAR\16\CLS]
DEBUG STR NBVAR
runtime = NBVAR
DO
HIGH 14
PAUSE runtime
LOW 14
PAUSE runtime
LOOP
Comments
1) You've declared NBVAR as a single byte, yet you're trying to read 16 bytes into it.
2) You're reading characters into NBVAR and displaying them using DEBUG,
yet you're expecting PBasic to translate them into a numeric value.
PBasic doesn't do that.
3) If the PINK value can be greater than 255, you can't store it into a byte.
You need a word variable.
What you probably want to do is to convert the variable's value into a number directly
using one of the "formatters" in PBasic like DEC. Look at the description of these in
the PBasic manual under the SERIN command.
You will probably want to declare NBVAR as a word, then do "SERIN 7,396,[noparse][[/noparse]DEC NBVAR]".
This will skip non-numeric characters until a digit is found, then convert a series of digits
into a numeric value (at most 65535 ... 16-bit). It will stop at the first non-digit found
(and absorb the non-digit character). You can do the debug output with "DEBUG DEC NBVAR".
That worked perfectly [noparse]:)[/noparse]