'define variables (v = byte, w = word):
symbol wColor = w0 'b0 and b1
symbol wBright = w1 'b2 and b3
symbol vBright = b2
symbol vCmdFound= b4
symbol vStatus = b5
'...
Do
hsersetup B9600_8, %000 'setup hardware serial Baud rate to 9600, %00 = true inverted (idle high), clear the buffer
Pause 1500
wColor = -1 'set the var to a non-valid value
wBright = -1 'set the var to a non-valid value
HSerIn wColor 'read first byte from buffer
HSerIn wBright 'read second byte from buffer
if b1 = 0 Then 'valid character received for color (data is in b0)
wBright = wBright - 48
wBright = vLvls / 9 * wBright '* 28 'ASCII 0-9 range gives PWM range of 0 to 252'
vCmdFound = 100 'set the found number to 100; not valid
lookdown wColor,(82,114,71,103,66,98,87,119,80),vCmdFound
if vCmdFound <> 100 then
select case wColor
case 82,114,71,103,66,98,87,119 : gosub getPwmDuty
end select
select case wColor
case 82,114 : vStatus = 1 : vRedLvl = wBright : pwmduty pRed, wBright 'R or r
case 71,103 : vStatus = 1 : vGrnLvl = wBright : pwmduty pGreen, wBright 'G or g
case 66,98 : vStatus = 1 : vBluLvl = wBright : pwmduty pBlue, wBright 'B or b
case 87,119 : vStatus = 1 : vWhtLvl = wBright : pwmduty pWhite, wBright 'W or w
case 76 : gosub setLevel 'L for levels
case 80 : gosub togglePower 'P for Power
end select
sertxd( "Received ",#wColor," and ",#wBright,13,10)
hserout 0,("Cmd Rcvd")
end if
end if
Loop