;#Picaxe 18M2 Water drop controller, 4 drops controlled via numeric
;keypad and serial OLED screen interface.
symbol key_pos = b0
symbol key_value = b1
symbol solenoid = B.7
symbol COL1 = pin0
symbol COL2 = pin1
symbol COL3 = pin2
symbol ROW1 = B.0
symbol ROW2 = B.1
symbol ROW3 = B.2
symbol ROW4 = B.3
symbol dropDelay1 = w7
dropDelay1 = 0
symbol dropDelay2 = w8
dropDelay2 = 0
symbol dropDelay3 = w9
dropDelay3 = 0
symbol dropDelay4 = w10
dropDelay4 = 0
symbol dropDelay5 = w11
dropDelay5 = 0
symbol dropDelay6 = w12
dropDelay6 = 0
symbol dropDelay7 = w13
dropDelay7 = 0
init:
pause 500
serout C.7,N2400,(254,1) ;initialize OLED
pause 500
serout C.7,N2400,(254,129,"CHOOSE THE NUMBER") ;1st screen display
serout C.7,N2400,(254,195,"OF DROPS 1 - 4?")
serout C.7,N2400,(254,157,"_")
pause 500
let dirsB = 255
drops:
do
gosub GetTheKeyPressed
if key_value = 1 then goto DROPS1
if key_value = 2 then goto DROPS2
if key_value = 3 then goto DROPS3
if key_value = 4 then goto DROPS4
loop until key_value >0
return
DROPS1:
serout C.7,N2400,(254,157,"1");if 1 is keyed in it brings P1 on screen and the pause value ready for altering
pause 1000
serout C.7,N2400,(254,1)
pause 30
serout C.7,N2400,(254,134,"P1 -",254,139,#w7)
pause 30
do
gosub Get4DigitNumberIntoW7
loop until key_value > 0
goto mainA
return
DROPS2:
serout C.7,N2400,(254,157,"2");if 2 is keyed in it brings P1,P2 and P3 on screen and the pause values ready for altering
pause 1000
serout C.7,N2400,(254,1)
pause 30
serout C.7,N2400,(254,134,"P1 -",254,139,#w7)
serout C.7,N2400,(254,192,"P2 -",254,197,#w8)
serout C.7,N2400,(254,202,"P3 -",254,207,#w9)
pause 30
do
gosub Get4DigitNumberIntoW7
loop until key_value > 0
do
gosub Get4DigitNumberIntoW8
loop until key_value > 0
do
gosub Get4DigitNumberIntoW9
loop until key_value > 0
goto mainB
return
DROPS3:
serout C.7,N2400,(254,157,"3");if 3 is keyed in it brings P1, P2, P3, P4 and P5 on screen and the pause values ready for altering
pause 1000
serout C.7,N2400,(254,1)
pause 30
serout C.7,N2400,(254,134,"P1 -",254,139,#w7)
serout C.7,N2400,(254,192,"P2 -",254,197,#w8)
serout C.7,N2400,(254,202,"P3 -",254,207,#w9)
serout C.7,N2400,(254,148,"P4 -",254,153,#w10)
serout C.7,N2400,(254,158,"P5 -",254,163,#w11)
pause 30
do
gosub Get4DigitNumberIntoW7
loop until key_value > 0
do
gosub Get4DigitNumberIntoW8
loop until key_value > 0
do
gosub Get4DigitNumberIntoW9
loop until key_value > 0
do
gosub Get4DigitNumberIntoW10
loop until key_value > 0
do
gosub Get4DigitNumberIntoW11
loop until key_value > 0
goto mainC
return
DROPS4:
serout C.7,N2400,(254,157,"4");if 4 is keyed in it brings P1, P2, P3, P4, P5, P6 and P7 on screen and the pause values ready for altering
pause 1000
serout C.7,N2400,(254,1)
pause 30
serout C.7,N2400,(254,134,"P1 -",254,139,#w7)
serout C.7,N2400,(254,192,"P2 -",254,197,#w8)
serout C.7,N2400,(254,202,"P3 -",254,207,#w9)
serout C.7,N2400,(254,148,"P4 -",254,153,#w10)
serout C.7,N2400,(254,158,"P5 -",254,163,#w11)
serout C.7,N2400,(254,212,"P6 -",254,217,#w12)
serout C.7,N2400,(254,222,"P7 -",254,227,#w13)
pause 30
do
gosub Get4DigitNumberIntoW7
loop until key_value > 0
do
gosub Get4DigitNumberIntoW8
loop until key_value > 0
do
gosub Get4DigitNumberIntoW9
loop until key_value > 0
do
gosub Get4DigitNumberIntoW10
loop until key_value > 0
do
gosub Get4DigitNumberIntoW11
loop until key_value > 0
do
gosub Get4DigitNumberIntoW12
loop until key_value > 0
do
gosub Get4DigitNumberIntoW13
loop until key_value > 0
goto mainC
return
Get4DigitNumberIntoW7: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w7 = b1
serout C.7,N2400,(254,139,#w7)
pause 30
Gosub GetKeyPress : w7 = w7 * 10 + b1
serout C.7,N2400,(254,139,#w7)
pause 30
Gosub GetKeyPress : w7 = w7 * 10 + b1
serout C.7,N2400,(254,139,#w7)
pause 30
Gosub GetKeyPress : w7 = w7 * 10 + b1
serout C.7,N2400,(254,139,#w7)
pause 30
Return
Get4DigitNumberIntoW8: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w8 = b1
serout C.7,N2400,(254,197,#w8)
pause 30
Gosub GetKeyPress : w8 = w8 * 10 + b1
serout C.7,N2400,(254,197,#w8)
pause 30
Gosub GetKeyPress : w8 = w8 * 10 + b1
serout C.7,N2400,(254,197,#w8)
pause 30
Gosub GetKeyPress : w8 = w8 * 10 + b1
serout C.7,N2400,(254,197,#w8)
pause 30
Return
Get4DigitNumberIntoW9: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w9 = b1
serout C.7,N2400,(254,207,#w9)
pause 30
Gosub GetKeyPress : w9 = w9 * 10 + b1
serout C.7,N2400,(254,207,#w9)
pause 30
Gosub GetKeyPress : w9 = w9 * 10 + b1
serout C.7,N2400,(254,207,#w9)
pause 30
Gosub GetKeyPress : w9 = w9 * 10 + b1
serout C.7,N2400,(254,207,#w9)
pause 30
Return
Get4DigitNumberIntoW10: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w10 = b1
serout C.7,N2400,(254,153,#w10)
pause 30
Gosub GetKeyPress : w10 = w10 * 10 + b1
serout C.7,N2400,(254,153,#w10)
pause 30
Gosub GetKeyPress : w10 = w10 * 10 + b1
serout C.7,N2400,(254,153,#w10)
pause 30
Gosub GetKeyPress : w10 = w10 * 10 + b1
serout C.7,N2400,(254,153,#w10)
pause 30
Return
Get4DigitNumberIntoW11: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w11 = b1
serout C.7,N2400,(254,163,#w11)
pause 30
Gosub GetKeyPress : w11 = w11 * 10 + b1
serout C.7,N2400,(254,163,#w11)
pause 30
Gosub GetKeyPress : w11 = w11 * 10 + b1
serout C.7,N2400,(254,163,#w11)
pause 30
Gosub GetKeyPress : w11 = w11 * 10 + b1
serout C.7,N2400,(254,163,#w11)
pause 30
Return
Get4DigitNumberIntoW12: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w12 = b1
serout C.7,N2400,(254,217,#w12)
pause 30
Gosub GetKeyPress : w12 = w12 * 10 + b1
serout C.7,N2400,(254,217,#w12)
pause 30
Gosub GetKeyPress : w12 = w12 * 10 + b1
serout C.7,N2400,(254,217,#w12)
pause 30
Gosub GetKeyPress : w12 = w12 * 10 + b1
serout C.7,N2400,(254,217,#w12)
pause 30
Return
Get4DigitNumberIntoW13: ;Coding to change the pause time via keypad
Gosub GetKeyPress : w13 = b1
serout C.7,N2400,(254,227,#w13)
pause 30
Gosub GetKeyPress : w13 = w13 * 10 + b1
serout C.7,N2400,(254,227,#w13)
pause 30
Gosub GetKeyPress : w13 = w13 * 10 + b1
serout C.7,N2400,(254,227,#w13)
pause 30
Gosub GetKeyPress : w13 = w13 * 10 + b1
serout C.7,N2400,(254,227,#w13)
pause 30
Return
GetKeyPress:
' Wait until no key pressed
Do
Gosub GetTheKeyPressed
Loop Until b1 = 0
' Wait until key pressed
Do
Gosub GetTheKeyPressed
Loop Until b1 <> 0
Return
GetTheKeyPressed: ;Keypad scan coding
key_pos = 0
key_value = 0
High ROW1 : gosub ScanCol : low ROW1
High ROW2 : gosub ScanCol : low ROW2
High ROW3 : gosub ScanCol : low ROW3
High ROW4 : gosub ScanCol : low ROW4
Return
ScanCol:
if COL1 = 1 then : key_value = key_pos + 1 : endif
if COL2 = 1 then : key_value = key_pos + 2 : endif
if COL3 = 1 then : key_value = key_pos + 3 : endif
key_pos = key_pos + 3
if key_value = 11 then let key_value = 0 endif
return
mainA:
do
gosub GetTheKeyPressed
loop until key_value = 12 ; 12 is the # key on keypad and will start the run sequencw when pressed
goto main1
return
main1: ;Gives 1 drop from solenoid
high solenoid
pause dropdelay1
low solenoid
goto init
mainB:
do
gosub GetTheKeyPressed
loop until key_value = 12 ; 12 is the # key on keypad and will start the run sequencw when pressed
goto main2
return
main2: ;Gives 2 drops from solenoid
high solenoid
pause dropdelay1
low solenoid
pause dropdelay2
high solenoid
pause dropdelay3
low solenoid
goto init
mainC:
do
gosub GetTheKeyPressed
loop until key_value = 12 ; 12 is the # key on keypad and will start the run sequencw when pressed
goto main3
return
main3: ;Gives 3 drops from solenoid
high solenoid
pause dropdelay1
low solenoid
pause dropdelay2
high solenoid
pause dropdelay3
low solenoid
pause dropdelay4
high solenoid
pause dropdelay5
low solenoid
goto init
mainD:
do
gosub GetTheKeyPressed
loop until key_value = 12
goto main4
return
main4: ;Gives 4 drops from solenoid
high solenoid
pause dropdelay1
low solenoid
pause dropdelay2
high solenoid
pause dropdelay3
low solenoid
pause dropdelay4
high solenoid
pause dropdelay5
low solenoid
pause dropdelay6
high solenoid
pause dropdelay7
low solenoid
goto init