Hey Kurt,
I didn’t have to change much in your code to get it to work! Good job for off the top if your head. The pins can’t be tested in an if then command. So I scanned the 4 pins, stuffed them into variables, then made decisions based on the variables. It worked so well I went ahead and wrapped it into my other program. The radio is fully functional now! 8) It actually works very well. It won’t take much longer for me to get the others finished Thanks for your help with this! Thanks to EddieB as well!
I know there will be many improvements. Here is the code.
[code]; declare variables here
wButtonPulseWidth var word
keypress var byte
col1 var bit
col2 var bit
col3 var bit
col4 var bit
cha1 var word
cha2 var word
cha3 var word
cha4 var word
cha5 var word
cha6 var word
cha7 var word
; create variables for averaging code
index var byte
buffer1 var word(8)
buffer2 var word(8)
buffer3 var word(8)
buffer4 var word(8)
buffer5 var word(8)
buffer6 var word(8)
sum1 var word
sum2 var word
sum3 var word
sum4 var word
sum5 var word
sum6 var word
input p4
input p5
input p6
input p7
output p10
output p11
output p12
output p13
; initialize each buffer element, each sum, and then index to 0
for index = 0 to 7
buffer1(index) = 542
buffer2(index) = 542
buffer3(index) = 542
buffer4(index) = 542
buffer5(index) = 542
buffer6(index) = 542
next
sum1 = 4336
sum2 = 4336
sum3 = 4336
sum4 = 4336
sum5 = 4336
sum6 = 4336
index = 0
; initialize unused channels outside the main loop
cha7=1500
; chirpy squeak kinda thing
sound 9, [100\880, 100\988, 100\1046, 100\1175] ;musical notes, A,B,C,D.
; wake up the Matrix Orbital display module
;serout 8,i19200,[254, 66, 0] ;Backlight on, no timeout.
;serout 8,i19200,[254, 64, “The D-I-Y 2.4ghzRobot Radio Set!”] ;startup screen. Do only once…
pause 5000
serout 8,i19200, [254, 88] ;clear screen
; initialize the ppm output signal
low 15
; — top of main loop —
start:
high 11
high 12
high 13
low 10
col1 = in4
col2 = in5
col3 = in6
col4 = in7
if col1 = 0 then
wButtonPulseWidth = 1200; 1
keypress = “1”
elseif col2 = 0
wButtonPulseWidth = 1250; 2
keypress = “2”
elseif col3 = 0
wButtonPulseWidth = 1300; 3
keypress = “3”
elseif col4 = 0
wButtonPulseWidth = 1650; A
keypress = “A”
else
high 10
low 11
col1 = in4
col2 = in5
col3 = in6
col4 = in7
if col1 = 0 then
wButtonPulseWidth = 1350; 4
keypress = “4”
elseif col2 = 0
wButtonPulseWidth = 1400; 5
keypress = “5”
elseif col3 = 0
wButtonPulseWidth = 1450; 6
keypress = “6”
elseif col4 = 0
wButtonPulseWidth = 1700; B
keypress = “B”
else
high 11
low 12
col1 = in4
col2 = in5
col3 = in6
col4 = in7
if col1 = 0 then
wButtonPulseWidth = 1500; 7
keypress = “7”
elseif col2 = 0
wButtonPulseWidth = 1550; 8
keypress = “8”
elseif col3 = 0
wButtonPulseWidth = 1600; 9
keypress = “9”
elseif col4 = 0
wButtonPulseWidth = 1750; C
keypress = “C”
else
high 12
low 13
col1 = in4
col2 = in5
col3 = in6
col4 = in7
if col1 = 0 then
wButtonPulseWidth = 1150; 0
keypress = “0”
elseif col2 = 0
wButtonPulseWidth = 1900; F
keypress = “F”
elseif col3 = 0
wButtonPulseWidth = 1850 ; E
keypress = “E”
elseif col4 = 0
wButtonPulseWidth = 1800; D
keypress = “D”
else
wButtonPulseWidth = 1100; None is pushed
keypress = " "
endif
endif
endif
endif
; averaging expects that the a/d values are < 4096
; for each channel
; read the a/d
; subtract the previous value from 8 samples ago from the sum
; store the new value in the circular buffer
; add the new value to the sum
; divide the sum by 8 to get the average value
; convert joystick values 392 - 692 to servo values 1000uS - 2000uS
adin 2, cha1 ; right vertical 16
sum1 = sum1 - buffer1(index)
buffer1(index) = cha1
sum1 = sum1 + cha1
cha1 = sum1 / 8
cha1 = (((cha1*42)-6500)/10)
adin 3, cha2 ; right horizontal 17
sum2 = sum2 - buffer2(index)
buffer2(index) = cha2
sum2 = sum2 + cha2
cha2 = sum2 / 8
cha2 = (((cha2*42)-6500)/10)
adin 0, cha3 ; left vertical 18
sum3 = sum3 - buffer3(index)
buffer3(index) = cha3
sum3 = sum3 + cha3
cha3 = sum3 / 8
cha3 = (((cha3*42)-6500)/10)
adin 1, cha4 ; left horizontal 19
sum4 = sum4 - buffer4(index)
buffer4(index) = cha4
sum4 = sum4 + cha4
cha4 = sum4 / 8
cha4 = (((cha4*42)-6500)/10)
adin 18, cha5 ; Left slider
sum5 = sum5 - buffer5(index)
buffer5(index) = cha5
sum5 = sum5 + cha5
cha5 = sum5 / 8
cha5 = cha5 + 988
adin 19, cha6 ; Right slider
sum6 = sum6 - buffer6(index)
buffer6(index) = cha6
sum6 = sum6 + cha6
cha6 = sum6 / 8
cha6 = cha6 + 988
; finally increment the index and limit its range to 0 to 7.
index = (index + 1) & 7
; update the display module
branch index, [update1,update2,update3,update4,update5,update6,update7,update8]
update8:
update7:
serout 8, i19200, [254, 71, 11, 1, keypress]
goto makepulses
update6:
if cha6<1000 then update62
serout 8, i19200, [254, 71, 6, 2, dec cha6]
goto makepulses
update62:
serout 8, i19200, [254, 71, 6, 2, " ", dec cha6]
goto makepulses
update5:
if cha5<1000 then update52
serout 8, i19200, [254, 71, 6, 1, dec cha5]
goto makepulses
update52:
serout 8, i19200, [254, 71, 6, 1, " ", dec cha5]
goto makepulses
update4:
if cha4<1000 then update42
serout 8, i19200, [254, 71, 1, 2, dec cha4]
goto makepulses
update42:
serout 8, i19200, [254, 71, 1, 2, " ", dec cha4]
goto makepulses
update3:
if cha3<1000 then update32
serout 8, i19200, [254, 71, 1, 1, dec cha3]
goto makepulses
update32:
serout 8, i19200, [254, 71, 1, 1, " ", dec cha2]
goto makepulses
update2:
if cha2<1000 then update22
serout 8, i19200, [254, 71, 13, 2, dec cha2]
goto makepulses
update22:
serout 8, i19200, [254, 71, 13, 2, " ", dec cha2]
goto makepulses
update1:
if cha1<1000 then update12
serout 8, i19200, [254, 71, 13, 1, dec cha1]
goto makepulses
update12:
serout 8, i19200, [254, 71, 13, 1, " ", dec cha1]
goto makepulses
; build and send the ppm output
makepulses:
pulsout 15,800
pauseus ((cha12)-800)
pulsout 15,800
pauseus ((cha22)-800)
pulsout 15,800
pauseus ((cha32)-800)
pulsout 15,800
pauseus ((cha42)-800)
pulsout 15,800
pauseus ((cha52)-800)
pulsout 15,800
pauseus ((cha62)-800)
pulsout 15,800
pauseus ((wButtonPulseWidth*2)-800)
pulsout 15,800
; do it again ad infinitum
goto start [/code]