Syntax error

regpye

New Member
I have been having an issue that I have tried many times to solve without success, maybe someone with more experience can assist?


Code:
#picaxe 14M2

symbol LDRpin = C.4    ; LDR pin
symbol PumpPin = B.5   ; NFT Pump pin
symbol DayTime = 100   ; LDR reading for day time

start2:
  if readadc(LDRpin) >= DayTime then ; it's day time
      high PumpPin          ; turn on the pump
      pause 1000            ; pause for 1 second
  else                       ; it's night time
      low PumpPin           ; turn off the pump
      for b1 = 1 to 180 do  ; repeat 180 times (180 x 10 sec = 30 min)
          pause 10000       ; pause for 10 seconds
      next b1

      high PumpPin          ; turn on the pump for 5 minutes
      for b2 = 1 to 10
          pause 30000      ; pause for 30 seconds
      next b2
  endif
 

regpye

New Member
I am getting the error on this line and have tried many combinations to overcome the problem>

if readadc(LDRpin) >= DayTime then ; it's day time
 

papaof2

Senior Member
You can't use readadc in an IF statement. Look at the syntax in Manual 2.

Change your IF line to two lines:

readadc LDRpin, b6
if b6 >= DayTime then ; it's day time

and add "loop" at the end of the program

high PumpPin ; turn on the pump for 5 minutes
for b2 = 1 to 10
pause 30000 ; pause for 30 seconds
next b2
endif
loop

These changes have it working in PE5 and PE6.
 

PhilHornby

Senior Member
The following code passes the Syntax Check - but whether it does what you want or not, is another matter :unsure:

See the manual, re: Readadc -it takes a pin and a variable ... it doesn't return a value (like a function in other languages).

I removed the Start2: label - because that has special 'multi-tasking' meaning and replaced it with do ... loop

Finally, a superfluous do had crept into the for b1 = 180 statement

(You and @Papaof2 posted while I was typing ... but I've typed it in now - so I'm hitting "Post Reply" :) )


Rich (BB code):
#picaxe 14M2

symbol LDRpin = C.4    ; LDR pin
symbol PumpPin = B.5   ; NFT Pump pin
symbol DayTime = 100   ; LDR reading for day time

;start2:?
do
  readadc LDRpin,b0
  
  if b0 >= DayTime then ; it's day time
      high PumpPin          ; turn on the pump
      pause 1000            ; pause for 1 second
  else                       ; it's night time
      low PumpPin           ; turn off the pump
      for b1 = 1 to 180   ; repeat 180 times (180 x 10 sec = 30 min)
          pause 10000       ; pause for 10 seconds
      next b1

      high PumpPin          ; turn on the pump for 5 minutes
      for b2 = 1 to 10
          pause 30000      ; pause for 30 seconds
      next b2
  endif
loop
 

hippy

Technical Support
Staff member
Code:
for b1 = 1 to 180 do ; repeat 180 times (180 x 10 sec = 30 min)
    pause 10000      ; pause for 10 seconds
next b1
Does 180 * 10 seconds equal 30 minutes ? It does but it's not immediately obvious when your brain is just moving into gear at the start of the week.

One thing I would suggest is using a "PAUSE 60000" then you can have a minute long pause and then the loop count, in this case, can be a simple 30 and it's easier to tell at a glance that 30 * 60 seconds is indeed 30 minutes -

Code:
for b1 = 1 to 30     ; repeat 30 times (30 x 1 min = 30 min)
    pause 60000      ; pause for 60,000 milliseconds, 60 seconds, 1 minute
next b1
 

regpye

New Member
I removed the Start2: label - because that has special 'multi-tasking' meaning and replaced it with do ... loop

Finally, a superfluous do had crept into the for b1 = 180 statement
Thank Hippy,
this code is part of a program that has 4 starts, that is why the start2.
After several trials I managed to get it working, used a few different tetchiness, but I will check out all your codes from you and others because I can probably learn something at the same time.

You can't use readadc in an IF statement. Look at the syntax in Manual 2.

Change your IF line to two lines:

readadc LDRpin, b6
if b6 >= DayTime then ; it's day time
Thanks for that info, much appreciated.
 

regpye

New Member
This is what I ended up doing myself and I have it working ok. Maybe there is a better way to do it, but I am still learning.

start2:
b0 = 0 ; initialize b0 variable
low NFT_pump ; NFT pump off
pause 1000 ; wait 1 second only for test purposes
readadc C.4, b0 ; read LDR for night or day into variable b0
do
if b0 >= DayTime then Day; it's day time
if b0 <= DayTime then nighttime; it's night time

Day:
high NFT_pump ; turn on the pump
pause 100 ; pause for 0.1 second
readadc C.4, b0 ; read LDR for night or day into variable b0
if b0 <= DayTime then nighttime; it's night time
loop

nighttime:
low NFT_pump
for b9 = 1 to 1200 ; define off in minutes 40=1200
pause 2000 ; wait 2 seconds
next b9
high NFT_pump ; turn on the pump
for b8 = 1 to 150 ; define on in minutes 150=5 minutes
pause 2000 ; wait 2 seconds
readadc C.4, b0 ; read LDR for night or day into variable b0
if b0 >= DayTime then Day; it's day time
next b8
goto start2
 
Top