I have written some simple code to operate a small pump to flood my seedlings in a hydroponic grow tube.
The code works well, but there is a long time between flooding and I would like to add some code to the pump off cycle that will flash a LED on C.4 of a 08M2 chip and the flashing to decrease in time the closer to the end of the cycle. The idea is to be able to visualize how much time is left by seeing the flashes, short quick flashes would mean the time is nearly up, long slow flashes the cycle has just started .
I think it maybe easy to do using the timing cycle in my code, but I have no idea of how to implement that feature.
I am using an LDR to test for night and day because there are longer off times at night time, so the code will need to work in both instances of day and night.
My existing code:
The code works well, but there is a long time between flooding and I would like to add some code to the pump off cycle that will flash a LED on C.4 of a 08M2 chip and the flashing to decrease in time the closer to the end of the cycle. The idea is to be able to visualize how much time is left by seeing the flashes, short quick flashes would mean the time is nearly up, long slow flashes the cycle has just started .
I think it maybe easy to do using the timing cycle in my code, but I have no idea of how to implement that feature.
I am using an LDR to test for night and day because there are longer off times at night time, so the code will need to work in both instances of day and night.
My existing code:
Code:
; 08M2+ chip
; Seedling pump cycle
main:
low c.0 ;pump is on green led off
low c.2 ;day time yellow led off
low c.4 ;red led off to be used to indicate time remaining for off time.
readadc C.1,b0 ; read LDR for night or day into variable b0
if b0 > 100 then day ; if b0 > 100 then do day
if b0 < 100 then night ; if b0 < 100 then do night
day:
high c.0 ;pump is on green led on
low c.2 ; day time yellow led off
for b0 = 1 to 1 ;set number of minutes depends on filling time.
wait 50 ;wait 50 seconds
if b0 < 100 then night ; if b0 < 100 then do night
next b0
off_time_day:
low c.0 ; pump off
for b1 = 1 to 60 ;set number of minutes time for draining and roots breathing air.
if b0 < 100 then night ; if b0 < 100 then do night
wait 60 ;wait 60 seconds
next b1
goto main
night:
high c.2 ; night time yellow led on
for b2 = 1 to 1 ;set number of minutes depends on filling time.
wait 50 ;wait 50 seconds
if b0 > 100 then day ; if b0 > 100 then do day
next b2
off_time_night:
low c.0 ; pump off
high c.2 ; day time yellow led on
for b3 = 1 to 120 ;set number of minutes time for draining and roots breathing air.
if b0 > 100 then day ; if b0 > 100 then do day
wait 60 ;wait 60 seconds
next b3
goto main
Last edited: