Question about syntax

if pin1 = 1 and pin3 = 1 and playflag = 0 then pause 9 start_count
I get a syntax error with the above line, I tried it like this

if pin1 = 1 and pin3 = 1 and playflag = 0 then
pause 9, then start_count
What is the way to format it so that it works - if pin 1 and pin 3 are high, playflag = 0, pause 9, then start count.

Thanks!
 

westaust55

Moderator
As a first comment, when putting multiple commands on a single line then please insert colons ([b[]:[/b]) as newline separators.
Yes, the PE will accept a space on most occasions but using the intended character makes the code more readable.
See PICAXE manual 2 page 6.
Newline
Commands are normally placed on separate lines. However if desired the colon (:) character can be use to separate multiple commands on a single line e.g.
if pin1 = 1 then : high 1 : else : low 1 : endif
So to your question:
Code:
if pin1 = 1 and pin3 = 1 and playflag = 0 then 
    pause 9
    GOTO start_count
ENDIF
The ENDIF statement is required so that the BASIC interpreter knows when the IF…THEN finishes in the case when the tests fail.
 
Last edited:

geoff07

Senior Member
the stray comma isn't needed!

You might make start_count a subroutine, and CALL it, so then control stays in the same path.
 

westaust55

Moderator
the stray comma isn't needed!
Fixed

Another option is to make the PAUSE command the first action in the Start_Count routine as it is going to happen regardless and then having the label name "Start_Count" immediately after the THEN would be valid and the GOTO and ENDIF not required.
 
Thanks guys, late night newb mistake, heh. What confused me is that I had the code like this:
if pin1 = 1 and pin3 = 1 and playflag = 0 then start_count
And it worked fine, so I thought just slipping the pause in between would work.

Anyway, now this brings me to another hurdle, basically the pause only needs to happen when pin3 goes high after pin3 was previously low, then when the program loops through start_count with pin3 still high the pause does not need to happen, if then pin3 goes low then next time pin3 goes high I need the pause to happen again just once until pin3 state changes again from low to high, and so on. Any idea how to do this, because I'm stumped!
 

geoff07

Senior Member
You could frequently check and save the value of pin3 in a variable so you can later check if it has been low. Or you could use an interrupt on pin3 going low to high. I suggest you try to flowchart it before coding as it is a bit convoluted and it isn't all that clear what you want.
 
Top