'
' PICAXE 18M2 CONNECTIONS
'
' leg 01 (C.2) (input2) r/x input
' leg 02 (C.3) (serial out)
' leg 03 (C.4) (serial in) connect to 0v
' leg 04 (C.5) (reset) tied to Vdd via 4k7
' leg 05 0V (Vss) 0v
' leg 06 (B.0) (output0) channel1
' leg 07 (B.1) (output1) channel2
' leg 08 (B.2) (output2) channel3
' leg 09 (B.3) (output3) channel4
' leg 10 (B.4) (output4) channel5
' leg 11 (B.5) (output5) channel6
' leg 12 (B.6) (output6) channel7
' leg 13 (B.7) (output7) channel8
' leg 14 +V (Vdd) +5v
' leg 15 (C.6)
' leg 16 (C.7)
' leg 17 (C.0)
' leg 18 (C.1)
'===============================================================
symbol full_stick=b1 'number of frames the joystick threshold has been exceeded.
symbol ONkount=b2 'number of times the joystick has been 'jabbed'
symbol OFFkount=b3
symbol centre_stick=b4 'number of frames the joystick has been centre position
symbol cownt=b6 'number of elapsed frames before each volume adjustment
symbol quartersec=b7
symbol halfsec=b8
symbol wholesec=b9
symbol flashblue=b10
'measure TX frame rate for setting time periods - some new transmitters have 6.7mSec
'rate rather than the traditional 20mSec
init:
let dirsB = %11111111
let pinsB = %10000000
pause 500
let pinsB = %00000000
pause 10
pulsin 0,1,b0
if b0>75 and b0<225 then
count 0,1000, wholesec
halfsec=wholesec/2
quartersec=wholesec/4
else
goto init
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' MAIN PROGRAM STARTS HERE
'-------------------------------------------------------------------------------------------------------------------------------------------------------
main:
full_stick=0 'reset frame count timer
pulsin 0,1,b0 'read joystick position
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' PROCESS JABS TO ON SIDE OF NEUTRAL
'-------------------------------------------------------------------------------------------------------------------------------------------------------
if b0>170 then 'joystick beyond threshold?
ONkount=ONkount+1 max 9 'increment jab counter
' if ONkount = 9 then skip6
' if ONkount = 4 then flashon
centre_stick=0 'reset neutral position timer
skip: 're-read joystick position, looping until released or held
pulsin 0,1,b0 'read joystick position
full_stick=full_stick+1 max 255 'increment frame count timer
if b0>165 then 'is joystick still above threshold?
'note 170-165=50uSec hysteresis
if full_stick>halfsec then 'yes, above threshold, but is it 'held'?
'yes it's held
ONkount=ONkount-1 'counts 1 to 8 but ports 0 to 7
if ONkount = 8 then skip6
if ONkount = 3 then flashon
high ONkount 'turn on appropriate port
skip2: 'now wait for joystick to be released
pulsin 0,1,b0 'read joystick position
if b0>165 then skip2 'joystick still held? note 170-165=50uSec hyst.
ONkount=0 'reset jab counter
OFFkount=0
end if
goto skip 'no,it's not "held" (1/2 sec), but neither is it released
end if 'so loop round again until one or the other
end if
full_stick=0
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' PROCESS JABS TO OFF SIDE OF NEUTRAL
'-------------------------------------------------------------------------------------------------------------------------------------------------------
if b0<130 then 'joystick beyond threshold?
OFFkount=OFFkount+1 max 9 'increment jab counter
if OFFkount = 9 then skip5
if OFFkount = 4 then flashoff
centre_stick=0 'reset neutral position timer
skip3: 're-read joystick position, looping unti released or held
pulsin 0,1,b0 'read joystick position
full_stick=full_stick+1 max 255 'increment frame count timer
if b0<135 then 'is joystick still above threshold?
'note 170-165=50uSec hysteresis
if full_stick>halfsec then 'yes, above threshold, but is it 'held'?
OFFkount=OFFkount-1
low OFFkount
skip4: 'now wait for joystick to be released
pulsin 0,1,b0 'read joystick position
if b0<135 then skip4 'joystick still held? note 170-165=50uSec hyst.
OFFkount=0
ONkount=0 'reset jab counter
end if
goto skip3 'no,it's not held, but neither is it released
'so loop round again until one or the other
skip5:
let pinsB=%00000000 'Turn all channels off
OFFkount=0
ONkount=0 'reset jab counter
goto skip3
skip6:
let pinsB=%11111000
OFFkount=0
ONkount=0 'reset jab counter
flashon:
flashblue=1
gosub flash
flashoff:
flashblue=0
gosub flash
flash:
if flashblue=1 then
high b.3
else
low b.3
return
end if
end if
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------
' PROCESS TIME SPENT WITH STICK IN NEUTRAL POSITION
'-------------------------------------------------------------------------------------------------------------------------------------------------------
if b0>140 and b0<160 then 'is stick in neutral position?
centre_stick=centre_stick+1 max 255 'yes,increment neutral counter preventing
'overflow
end if
if centre_stick>wholesec then 'stick has been in neutral for one second
ONkount=0 'reset jab counters
OFFkount=0
end if
'-------------------------------------------------------------------------------------------------------------------------------------------------------
goto main
'-------------------------------------------------------------------------------------------------------------------------------------------------------