I have been working on several simple versions of this code, trying to learn as I go.
Some of you have helped me in the past recently and I appreciate that a lot, but I am still trying to learn other things so I am using the same project to do this.
While working through this code I came up with something rather strange that I can't work out why.
There are two parts of the code that are almost identical, one part works fine and the other part a section of it is really off.
I am referring to the w4 section of the code which is suppose to reduce by 10 on each cycle, but it does not. I have commented in the code where.
The best way to see what I am talking about is to run the code in the simulator using the c.1 slider to change the light value from say 110 to 90 to give a simulation of either day or night. It is the night time cycle that has the problem. I have commented out some of the values to a lower value of some settings to reduce the timing for simulation speed.
I just want to know why this is happening, not to have a complete re-coding done as I am using this example in my learning.
Some of you have helped me in the past recently and I appreciate that a lot, but I am still trying to learn other things so I am using the same project to do this.
While working through this code I came up with something rather strange that I can't work out why.
There are two parts of the code that are almost identical, one part works fine and the other part a section of it is really off.
I am referring to the w4 section of the code which is suppose to reduce by 10 on each cycle, but it does not. I have commented in the code where.
The best way to see what I am talking about is to run the code in the simulator using the c.1 slider to change the light value from say 110 to 90 to give a simulation of either day or night. It is the night time cycle that has the problem. I have commented out some of the values to a lower value of some settings to reduce the timing for simulation speed.
I just want to know why this is happening, not to have a complete re-coding done as I am using this example in my learning.
Code:
#Picaxe 08M2
;#Terminal 4800
#No_Data
; .-----__-----.
; -| V+ 0V |-
; -| SI C.0 |---> Pump
; Day LED <---| C.4 C.1 |<--- LDR
; -| C.3 C.2 |---> Night LED
; `------------'
let w1 = 4300
let w2 = 2000
let w3 = 4300
let w4 = 2000
main:
readadc C.1,b0 ; read LDR for night or day into variable b0
if b0 > 105 then Day
if b0 < 95 then night
if b0 > 96 and b0 < 104 then waiting
waiting:
wait 6
goto main
Day:
high c.0 ; pump is on, green LED is on
low c.2 ; yellow led off
low c.4 ; red led off
for b2 = 1 to 10;0 ; 100 commented to reduce for simulation time
pause 250 ; wait 25 seconds
sertxd("Day Time pump is on ", #b2,13,10)
next b2
sertxd("Day Time pump is off ",13,10)
off_time_day:
readadc C.1,b0 ; read LDR for night or day into variable b0
if b0 < 95 then Night ; if b0 < 100 then do night
for b3 = 1 to 3;0 ; 30 commented to reduce for simulation time
gosub off_time
next b3
; turn pump on again for second time
high c.0 ; pump is on, green LED is on
low c.2 ; yellow led off
low c.4 ; red led off
for b2 = 1 to 10;0 ; 100 commented to reduce for simulation time
pause 250 ; wait 25 seconds
sertxd("Day Time pump is on ", #b2,13,10)
readadc C.1,b0 ; read LDR for night or day into variable b0
if b0 < 95 then Night ; if b0 < 100 then do night
next b2
sertxd("Day Time pump is off ",13,10)
for b3 = 1 to 3;0 ; 5 cycles per hour so times by hours wanted 5x6 = 30 = 6 hours commented to reduce for simulation time
gosub off_time
next b3
goto main
Night:
low c.0
for b3 = 1 to 50 ; 5 cycles per hour so times by hours wanted 5x10 = 50 =10 hours
gosub night_off_time
readadc C.1,b0 ; read LDR for night or day into variable b0
if b0 > 104 then Day ; if b0 > 104 then do Day
next b3
goto main
off_time: ; 12 minute cycle
for b8 = 1 to 200
low c.0
high c.4
pause w2
low c.4
pause w1
w1 = w1 - 15
w2 = w2 - 10
sertxd(" day off Time ",#w1, " : ", #w2, " : ",13,10)
next b8
return
night_off_time: ; 12 minute cycle
for b9 = 1 to 200
low c.0
high c.4
pause w4
low c.4
pause w3
w3 = w3 - 15
w4 = w4 - 10 ; SOMETHING WRONG HERE counts up randomly instead of down by 10
sertxd("night off Time ",#w3, " : ",#w4, " : ",13,10)
next b9
return