bfgstew
Senior Member
At last some success, I have it working now, coding is a bit of a mess as I had to do a set up with the code for the bargraph on a timed loop, let that go to the keypad routine to enter the triggerthreashold value, then go to a 'copy' of the first bargraph routine so it will run the bargraph so you can see what's happening, sounds confusing but it works!
Now I have this working, I can have a go at trying the modulated version and the laser version, should be fun............................
Code:
#slot2
#freqm4
;#PICAXE 28X2 photogate
symbol SOUND_ON = C.0
symbol CAMERA = C.1
symbol FLASH = C.2
symbol SOUND_IN = A.3
symbol LIGHT_ON = C.4
symbol PG_ON = C.5
symbol TIMER_LED = C.6
symbol READY_LED = C.7
symbol LIGHT_IN = A.0
symbol PG_IN = A.1
symbol SOLENOID = A.2
symbol COL2 = pinB.0
symbol ROW1 = B.1
symbol COL1 = pinB.2
symbol ROW4 = B.3
symbol COL3 = pinB.4
symbol ROW3 = B.5
symbol ROW2 = B.6
symbol DROPS_LED = B.7
symbol key_pos = b0 ; VARIABLES CONFIGURATION
symbol key_value = b1
symbol readvar = b4
symbol length = b5
symbol loopcounter = b6
symbol charactercounter = b7
symbol readvar1 = b8
symbol triggerthreashold = b10
symbol lcdsize = 20
setfreq em16
INIT:
let b10 = 0
let b11 = 0
let b0 = 0
let b1 = 0
let b4 = 0
let b5 = 0
let b6 = 0
let b7 = 0
serout C.3,N2400_16,(254,1)
pause 30
serout C.3,N2400_16,(254,128,"TURN POT TO DESIRED")
serout C.3,N2400_16,(254,192,"POSITION, THEN ENTER")
serout C.3,N2400_16,(254,148,"THE 'COPY' VALUE INTO")
serout C.3,N2400_16,(254,212,"THREASHOLD THEN HIT #")
pause 3000
serout C.3,N2400_16,(254,1)
pause 30
serout C.3,N2400_16,(254,128,"THE LOWER THE NUMBER")
serout C.3,N2400_16,(254,192,"THE HIGHER THE SENS")
serout C.3,N2400_16,(254,148,"THE HIGHER THE NUMBER")
serout C.3,N2400_16,(254,212,"THE LOWER THE SENS")
do
gosub GKP
loop until key_value = 12
SETTING:
serout C.3,N2400_16,(254,1)
pause 50
high C.5
pause 50
serout C.3, N2400_16, (254, 64, 32, 32, 32, 32, 32, 32, 32, 32) ; BLANK CHARACTER (0)
serout C.3, N2400_16, (254, 72, 48, 48, 48, 48, 48, 48, 48, 48) ; 1st segment = (1)
serout C.3, N2400_16, (254, 80, 56, 56, 56, 56, 56, 56, 56, 56) ; 1st and 2nd segment = (2)
serout C.3, N2400_16, (254, 88, 60, 60, 60, 60, 60, 60, 60, 60) ; 1st, 2nd and 3rd segment = (3)
serout C.3, N2400_16, (254, 96, 62, 62, 62, 62, 62, 62, 62, 62) ; 1st, 2nd, 3rd and 4th segment = (4)
serout C.3, N2400_16, (254, 104, 63, 63, 63, 63, 63, 63, 63, 63); whole block = (5)
do
readadc A.1,readvar
length = lcdsize * 6 - 1 * readvar / 255 + 1
readvar1 = readvar * 75 / 100
serout C.3,N2400_16,(254,128," SENSITIVITY")
serout C.3,N2400_16,(254,192,#triggerthreashold," "," THREASHOLD",254,148,#readvar1," ","COPY",254,158,#readvar," ","ACTUAL",254,212)
charactercounter = lcdsize
do
if length => 6 then
serout C.3,N2400_16,(13)
length = length - 6
elseif length = 5 then
serout C.3,N2400_16,(13)
length = length - 5
else
exit
end if
dec charactercounter
loop
readvar = length + 8
serout C.3,N2400_16,(readvar)
for loopcounter = 0 to charactercounter
serout C.3,N2400_16,(32)
next
inc b11
loop until b11 = 50 gosub TT7
main6:
do
readadc A.1,readvar
length = lcdsize * 6 - 1 * readvar / 255 + 1
readvar1 = readvar * 75 / 100
serout C.3,N2400_16,(254,128," SENSITIVITY")
serout C.3,N2400_16,(254,192,#triggerthreashold," "," THREASHOLD",254,148,#readvar1," ","COPY",254,158,#readvar," ","ACTUAL",254,212)
charactercounter = lcdsize
do
if length => 6 then
serout C.3,N2400_16,(13)
length = length - 6
elseif length = 5 then
serout C.3,N2400_16,(13)
length = length - 5
else
exit
end if
dec charactercounter
loop
if readvar =< triggerthreashold then goto main66
readvar = length + 8
serout C.3,N2400_16,(readvar)
for loopcounter = 0 to charactercounter
serout C.3,N2400_16,(32)
next
loop
main66:
high camera : high flash
pause 100
low camera : low flash
low READY_LED
low PG_ON
goto Init
GKP:
Do
Gosub GTKP ' Wait until no key pressed
Loop Until key_value = 0
Do
Gosub GTKP ' Wait until key pressed
Loop Until key_value <> 0
If key_value = 11 Then
key_value = 0
End If
Return
GTKP: ;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
return
TT7:
high READY_LED
let b11 = 0
For b33 = 1 to 4
Gosub GKP
if key_value = 12 then goto main6
pause 30
b10 = b10 * 10 + b1
serout C.3,N2400_16,(254,192,#b10)
pause 30
next b33
goto main6