The Code

Still cleaning it up....but it works.

 

#picaxe 28x2
'3-28-2010

'out c.3 Z8
'out 7 Z1
'out 6 Z2
'out 5 Z3
'out 4 Z4
'out 3 Z3
'out 2 Z2
'out 1 Z1
'in c.2 butt 1 to access menu/run prog
'in c.1 butt 2 to increment thur menu
'in c.0 butt 3
'in c.4 trigger for turnon


b1=1 ' set first day   <------------
b2=0  ' day counter
b11=0   ' photo cell value
b13=0  'no of days cycled
b14=100 ' daylight trigger value for readadc
b6=0   ' day variable 

b0=60 ' base delay
b20=100 ' multiplier  - 60 for one minute

b3=b0'  Rose
b4=b0' ' top lilac
b5=b0  'bot lilac
b7=b0 ' garden
b8=b0 ' hill
b9=b0 ' front lilac garden
b10=b0 ' front lower hill area
'w19      used as variable 
'w18      changed for each zone

b15=1  ' set to auto recycle
b16=0 ' cycle 
b17=0   '  temporary variable

pause 5000
SETFREQ m8
goto begin

Cycling: '  system cycling

high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("- Cycling mode - ",#b11)
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Cycle ",#b1," day ")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Turn on main")
gosub clsb1
pause 4000
b1=b1+1
gosub firstdy
gosub waitnt
gosub waitdy
gosub secdy
gosub waitnt
gosub waitdy
goto cycling

Begin:
readadc 0, b11
if b16=10 then gosub rt
low 7:low 6:low 5:low 4:low 3:low 2: low 1
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD 
pause 100:high 0:pause 100:SEROUT 0,t9600,("Water Control ",#b11)
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","") 
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Waiting start cycle")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","(Press 1 for menu)")

bb:
if pinc.2=1 then goto menu 'check for button 1 press or timer
high c.4:pause 200:low c.4 :pause 200' flash keep alive
pause 200:goto bb

menu:
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
low 7:low 6:low 5:low 4:low 3:low 2:low 1
pause 100:high 0:pause 100:SEROUT 0,t9600,("  -Menu-")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 1 for setup")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 2  ")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 3 First dy")
jj:
pause 200
if pinc.0=1 then goto cycling  ' first day water cycle
'if pinc.1=1 then gosub b6v
'if pinc.1=1 then goto cycling  '    second day water cycle
if pinc.2=1 then goto setup
goto jj

b6v:  '  set variable
b6=1:return

setup:
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("    -Menu- ")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 1 Curr Dura" )
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 2 Change Dur")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B 3 Restart")

j1:
pause 200
if pinc.0=1 then goto begin '  button 3
if pinc.1=1 then goto chgdur' button 2
if pinc.2=1 then goto dura ' button 1
goto j1

dura:  '  list durations
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("Roses ",#b3, " T-Lil " ,#b4 )
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","B-lil ",#b5, " Gard "  ,#b7 )
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Hill  ",#b8," F-Gard ",#b9)
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","F-low ",#b10)
pause 6000
goto setup

chgdur:' change durations
goto setup

Firstdy: ' Watering cycle ----------------------------------------------
high 7 ' turn on main valve
pause 2000
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 1-Roses")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b3)
gosub clsb3
w18=b3*b20
high 6:gosub dly:low 6:pause 200

high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 2-Top Lil")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b4)
gosub clsb3
w18=b4*b20
high 5:gosub dly:low 5:pause 200

high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD 
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 3- Below lil")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b5)
gosub clsb3
w18=b5*b20
high 4:gosub dly:low 4:pause 200

high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD  
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 4- Garden")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b7)
gosub clsb3
w18=b7*b20
high 3:gosub dly:low 3:pause 200
low 7 ' turn off main valve
return ' to cycling

secdy:  '  second day cycle
high 7: pause 1000' turn on main valve
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD 
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 5- Hill")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b8)
gosub clsb3
w18=b8*b20

high 2 :gosub dly:low 2:pause 200
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD 
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 6- F garden")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b9)
gosub clsb3

w18=b9*b20
high 1:gosub dly:low 1:pause 200
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD  
pause 100:high 0:pause 100:SEROUT 0,t9600,("Zone 7- Front Low")
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","Duration= ",#b10)
gosub clsb3

w18=b10*b20
high c.3 :gosub dly:low c.3:pause 200
low 7'  close main valve
gosub waitnt
gosub waitdy
goto Cycling


dly:  ' duration of water cycle-----------------------------------------
w19=0
tt:
high c.4:pause 200:low c.4 :pause 200
w19=w19+1
pause 1000
if w19>w18 then goto rt
gosub ck ' see if a button has been pushed
goto tt

ck:  'check for menu request
if pinc.0=1 then gosub menu' check button 3 push
return

rt:
b16=0
return

clsb1: ' LCD for button-1
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","?n","B-1 to abort")
return

clsb3:
pause 100:high 0:pause 100:SEROUT 0,t9600,("?n","?n","B-3 to abort")
return

waitnt:  ' waiting for dark
readadc 0, b11:pause 1000
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 200:high 0:pause 100:SEROUT 0,t9600,("waiting->nite ",#b11)
gosub clsb1
high c.4:pause 200:low c.4 :pause 200 ' flash keep alive
if pinc.2=1 then goto menu 'check for button 1 press or timer
if b11>100 then goto waitnt '  still dark
for b17=1 to 20:pause 65000:next '  make sure it is dark
if b11>100 then goto waitnt ' verify it is morning
return

waitdy:' waiting next daylite
readadc 0, b11:pause 1000
high 0:pause 100:SEROUT 0,t9600,("?f")  ' clear the LCD
pause 100:high 0:pause 100:SEROUT 0,t9600,("waiting->day ",#b11)
gosub clsb1
if pinc.2=1 then goto menu 'check for button 1 press or timer
high c.4:pause 200:low c.4 :pause 200 ' flash keep alive
pause 4000
if b11<100 then goto waitdy '  if less, still same day-continue loop
for b17=1 to 20:pause 65000:next '  make sure it is morning
if b11<100 then goto waitdy ' verify it is morning
'  it is dark
return