Syntax error

Gramps

Senior Member
What is the reason for this Syntax error?

code:
;LEDs light when Pot reaches certain value
#picaxe 28x2
#no_data
#no_table

symbol LED1 = C.0
symbol LED2 = C.1
Symbol LED3 = C.2
Symbol LED4 = C.3
Symbol POT1 = 13 ;B.5
Symbol POT_value = b1

Main:

Readadc POT_value, b1

If b1 = > 50 THEN LED1
If b1 = > 100 THEN LED2
If b1 = > 150 THEN LED3
If b1 = > 200 THEN LED4
endif

goto main
 

PhilHornby

Senior Member
Something like this is closest I can get, to what you've written. It runs and does something in the simulator :unsure:
It's a bit late here (the birds are singing!), so I'm off to bed - I'm sure someone will be along shortly to help you refine this to do what you want.

Rich (BB code):
code:
;LEDs light when Pot reaches certain value
#picaxe 28x2
#no_data
#no_table

symbol LED1 = C.0
symbol LED2 = C.1
Symbol LED3 = C.2
Symbol LED4 = C.3
Symbol POT1 = 13 ;B.5
Symbol POT_value = b1

output LED1,LED2,LED3,LED4

Main:

Readadc POT_value, b1

If b1 => 50 THEN  : HIGH LED1 :endif
If b1 => 100 THEN : HIGH LED2 :endif
If b1 => 150 THEN : HIGH LED3 :endif
If b1 => 200 THEN : HIGH LED4 :endif


goto main
 

Flenser

Senior Member
1) You had a space from between "=" and ">" in the IF statements that needed to be removed
2) You can't code "THEN LED1". This is the same as "THEN C.0" which makes no sense as there is no command "C.0" to turn on a LED. It needs to be "HIGH C.0" if you are using the C.0 syntax for the pin.
3) Each of your IF statements needed to have it's own ENDF

This code is untested but should progressively turn the LEDs on as the POT is turned up and progressively turn the LEDs off as the POT is turned down:
Code:
If b1 => 50 THEN HIGH LED1 ELSE LOW LED1 ENDIF
If b1 => 100 THEN HIGH LED2 ELSE LOW LED2 ENDIF
If b1 => 150 THEN HIGH LED3 ELSE LOW LED3 ENDIF
If b1 => 200 THEN HIGH LED4 ELSE LOW LED4 ENDIF
4) You have defined "POT_value=b1" so your READADC command "Readadc POT_value, b1" is the same as "Readadc b1, b1" which is probably not what you intended.
From your comment ";B.5' it looks like the POT is attached to B.5 so the commands for your SYMBOL POT1 and READADC should be:
Code:
Symbol POT1 = B.5
Readadc POT1, b1
 

Gramps

Senior Member
Something like this is closest I can get, to what you've written.
PhilHornby, Thank you for your help!

This code is untested but should progressively turn the LEDs on as the POT is turned up and progressively turn the LEDs off as the POT is turned down:
And thanks Flenser for the step by step answer!
I'm commuting every week between our home in South Carolina and the Rescue Mission in Fort Myers Florida but hope to hook up the hardware and try out your code soon
Gramps
 
Top