Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By lew247
#51197 I'm very new to ESp8266 and I'm "trying" to learn how to use it
I'm having trouble with the SERIALINPUT command
What I want to do is have the program wait until it receives an input on the serial port and then CHECK the input to see if it says a specific character or phrase
and IF it contains that character or phrase then carry on with another section of program [gosub]
IF the character or phrase is incorrect it carries on waiting for the correct input

Something along the lines of this
Code: Select all  KeepSearching:
  Do
  SERIALINPUT                               ' get a  record
  Loop Until arg$(0) = "start"               ' we only want the start record
  Print "Searching For start character"
  GoTo KeepSearching                       ' go back and keep looking


Is it possible to have an example of how to do this please?

I'm using V3.0 Alpha 12

Thanks
User avatar
By Mmiscool
#51231 You could use the serialbranch branch command. Works like an interrupt and triggers when receiving characters over the serial.

In the branch you can use the input command to grab the text. it must end with a carage return line feed for the input command to stop blocking.


Code: Select allserialbranch [branchLabel]
User avatar
By lew247
#51243 I did try SERIAL INPUT first but couldn't get it working
I tried it again with this code

do
KeepSearching
Do
serialbranch [input] ' get a record
Loop Untilleft(1) = "$" ' we only want the start record
Print "Searching For start character"
GoTo KeepSearching ' go back and keep looking
loop
loop

'main program here

[input]
let a$ = serialinput
if a$ = "$ then
else loop
endif
return


Any ideas how to get it working?

The error is

Code: Select allloop {until | while} not valid
Halted at line 5


DO I need Loop Untilleft(1) = "$" where I have it or in the sub? or have I totally got it wrong in how I'm trying to do it?

I want it to check for a serial input and when it receives "$" it's a genuine input and then to carry on with the program
User avatar
By lew247
#51247 I've also tried this

Do
serialbranch [input] ' get a record
Print "Searching For start character"
loop
'main program here
[input]
do
let a$ = serialinput
if a$ left(1) = "*" then
else loop
endif
return


It fails with the error
Code: Select allSearching For start character
loop {until | while} not valid
Halted at line 4


I've also tried this
Do
serialbranch [input] ' get a record
Print "Searching For start character"
IF A$ LEFT(1) = "$" THEN
GOSUB TODAY
ELSE
LOOP
END IF
'main program here
'TODAY sub here

[input]
let a$ = serialinput
return


This again fails with the error
Code: Select allSearching For start character
Syntax error in if command
Halted at line 4
Last edited by lew247 on Fri Jul 22, 2016 8:38 am, edited 1 time in total.