if then syntax error message.

#1
Hi all
I am a new be to this and have only coded in basic 17 years ago. So I am a non informed person.

Here is my situation I am trying to implement a monitor for my sump pump systems. Right now it is strictly to watch and not control the pumps. I have written a piece of code (first ever for this) which gives me a syntax error at the if then. What I am trying to do is monitor an input and when it goes lo have it turn on an output to light a led. I am going to attach the code.

#picaxe 18m2
symbol Float_Switch = pinb.2 'float sw. input lo = switch on
symbol Serial_Out = c.3
symbol Serial_In = c.4
symbol Test_Mode = b.0 'tests leds and sounder and ext alarm flashers
symbol Pump_On = c.2 'goes hi when pump has 120 volts
symbol OverFlow_Float_Switch = pinb.3 'goes lo whn over flow sw on
symbol Motor_Current = b.4 'Current loop input to ADC
symbol Motor_Stall_Led = b.5 'Led indicates stall goes low stall
symbol Motor_running_Led = b.6 'Led indicates normal current goes lo when running
symbol Piezo_sounder = b.7
symbol Ext_Test_Mode = c.6 'Allows ext control of test mode
symbol Alarm_Mode = c.7 'Alarm when over current, loss of power '' ; motor over flow sw is on goes high on alarm
symbol Pump_On_Led = c.0 'On when power to pump and current from b.4
symbol Pump_Fail_Led = c.1 'On when no power to pump and no current from b.4
symbol float_sw = b4
;power on test mode
POWER_TEST:
pinc.5 = 1 'turn on test led
pause 1000
pinc.2 = 1 'turn on oferflow led
pause 1000
pinc.0 = 1 'turn on pump on led
pause 1000
pinc.1 = 1 'turn on pump fail led
pause 1000
pinc.7 = 1 'turn on alarm led
pause 3000 'all leds on for 3 seconds
pinc.7 = 0
pause 550 'Turn all leds off after pause
pinc.1 = 0
pause 550
pinc.1 = 0
pause 550
pinc.0 = 0
pause 550
pinc.2 = 0
pause 550
pinc.5 = 0
goto MAIN
MAIN:
if Float_Switch = 0 then Pump_On_Led = 1 'main float switch is on
'pump on led is on
if pinb.3 = 0 then endif 'overflow loat switch is on
'overflow led on

Thank you so much and look forward to an answer to a obvious question doing something wrong.

Al
 

edmunds

Senior Member
#2
if [expression] then
something happens
endif

or

if [expression] then : something happens : endif

: stands for line break and the line break HAS to be there.

I would have re-written your code to help, but some logic seems missing. Perhaps post some more info on the project, schematics.

Good luck,

Edmunds
 

hippy

Technical Support
Staff member
#4
And if you are setting pins with commands such as "pinC.5=1" you will need to make those pins outputs with "dirC.5=1" or "dirsC=" commands.

Your "if Float_Switch = 0 then Pump_On_Led = 1" will not pass Syntax Check with 'Pump_On_Led' defined as a pin (C.0); you need to define that as "pinC.0" if an input or "outpinC.0" when used as an output as you are doing.

It is probably better to write some smaller programs first, get those working, and gain a fuller understanding of the PICAXE, before embarking on more complicated code. Turning a LED on when a button is pushed or a switch is set, and off when not, is a good start.
 

techElder

Well-known member
#6
And ...

When posting on the forum, it is better to wrap the code in your post with the HTML tags called [code] [/code].

This results in the display of your code looking like this:

Code:
MAIN:
if Float_Switch = 0 then Pump_On_Led = 1 'main float switch is on
'pump on led is on
if pinb.3 = 0 then endif 'overflow loat switch is on
'overflow led on
 

BESQUEUT

Senior Member
#7
Maybe something like this :
Code:
[color=Navy]#picaxe [/color][color=Black]18m2[/color]
[color=Blue]symbol [/color][color=Purple]Float_Switch [/color][color=DarkCyan]= [/color][color=Purple]pinb.2  [/color][color=Green]'float sw. input lo = switch on     [/color]
[color=Blue]symbol Serial_Out [/color][color=DarkCyan]= [/color][color=Blue]c.3
symbol Serial_In [/color][color=DarkCyan]= [/color][color=Blue]c.4
symbol      Test_Mode [/color][color=DarkCyan]= [/color][color=Blue]b.0   [/color][color=Green]'tests leds and sounder and ext alarm flashers  [/color]
[color=Blue]symbol      Pump_On [/color][color=DarkCyan]= [/color][color=Blue]c.2     [/color][color=Green]'goes hi when pump has 120 volts[/color]
[color=Blue]symbol      [/color][color=Purple]OverFlow_Float_Switch [/color][color=DarkCyan]= [/color][color=Purple]pinb.3      [/color][color=Green]'goes lo whn over flow sw on[/color]
[color=Blue]symbol      Motor_Current [/color][color=DarkCyan]= [/color][color=Blue]b.4     [/color][color=Green]'Current loop input to ADC[/color]
[color=Blue]symbol      Motor_Stall_Led [/color][color=DarkCyan]= [/color][color=Blue]b.5   [/color][color=Green]'Led indicates stall goes low stall [/color]
[color=Blue]symbol Motor_running_Led [/color][color=DarkCyan]= [/color][color=Blue]b.6      [/color][color=Green]'Led indicates normal current goes lo when running[/color]
[color=Blue]symbol Piezo_sounder [/color][color=DarkCyan]= [/color][color=Blue]b.7    
symbol      Ext_Test_Mode [/color][color=DarkCyan]= [/color][color=Blue]c.6     [/color][color=Green]'Allows ext control of test mode[/color]
[color=Blue]symbol      Alarm_Mode [/color][color=DarkCyan]= [/color][color=Blue]c.7  [/color][color=Green]'Alarm when over current, loss of power '' ;    motor over flow sw is on goes high on alarm[/color]
[color=Blue]symbol      Pump_On_Led [/color][color=DarkCyan]= [/color][color=Blue]c.0 [/color][color=Green]'On when power to pump and current from b.4[/color]
[color=Blue]symbol      Pump_Fail_Led [/color][color=DarkCyan]= [/color][color=Blue]c.1     [/color][color=Green]'On when no power to pump and no current from b.4[/color]
[color=Blue]symbol      [/color][color=Purple]float_sw [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]

[color=Green];power on test mode[/color]

[color=Purple]pinc.5 [/color][color=DarkCyan]= [/color][color=Navy]1  [/color][color=Green]'turn on test led[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Purple]pinc.2 [/color][color=DarkCyan]= [/color][color=Navy]1  [/color][color=Green]'turn on overflow led[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Purple]pinc.0 [/color][color=DarkCyan]= [/color][color=Navy]1  [/color][color=Green]'turn on pump on led[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Purple]pinc.1 [/color][color=DarkCyan]= [/color][color=Navy]1  [/color][color=Green]'turn on pump fail led[/color]
[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]1  [/color][color=Green]'turn on alarm led[/color]
[color=Blue]pause [/color][color=Navy]3000  [/color][color=Green]'all leds on for 3 seconds[/color]
[color=Purple]pinc.7 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]pause [/color][color=Navy]550   [/color][color=Green]'Turn all leds off after pause[/color]
[color=Purple]pinc.1 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]pause [/color][color=Navy]550[/color]
[color=Purple]pinc.1 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]pause [/color][color=Navy]550[/color]
[color=Purple]pinc.0 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]pause [/color][color=Navy]550[/color]
[color=Purple]pinc.2 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]pause [/color][color=Navy]550[/color]
[color=Purple]pinc.5 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]



[color=Blue]do
      if [/color][color=Purple]Float_Switch [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then      [/color][color=Green]'main float switch is on
            [/color][color=Blue]high Pump_On_Led  
      endif 
      
      [/color][color=Green]'pump on led is on
      [/color][color=Blue]if [/color][color=Purple]pinb.3 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then      [/color][color=Green]'overflow loat switch is on
      [/color][color=Blue]endif[/color]

[color=Green]'overflow led on[/color]
[color=Blue]loop[/color]
 
#8
I want to thank all who helped me I really appreciate it. I obviously need a lot of education, is there a place to get samples of working code for reference? I would also like to find the some reference books to refer to. I did get it to run through the simulator.

Thanks,
Best Al
 

AllyCat

Senior Member
#9
Hi,

There are some samples of code in the Code Snippetts section and more complete listings in the finished projects sections and of course the PICaxe User Manuals. If a forum search fails to find what you want, try the same keywords in Google with PICAXE added. ;)

But generally the best method is to ask questions in this Active Forum, where you will nearly always get genuine help (unlike some other forums).

Cheers, Alan.
 
Top