What I want to be able to do is toggle between auto and manual modes using the “A” button on the transmitter. When in “auto” mode, the servo should just rotate slowly back and forth. When in “manual” mode, I should be able to move the servo left and right using buttons “B” and “D”.
However, here is what is happening. When powered up, the board is in “manual” mode by default. When I press the “B” and “D” buttons, the servo initializes but then does not move while I keep the button pressed. I can alternate pushing the buttons, but all it does is initializes the servo to its start position. Note: the receiver output goes high when the corresponding button on the transmitter is pressed.
Even more vexing is what happens when I try to toggle back and forth between “auto” and “manual”. The first push on button “A” takes me into “auto” mode and the servo does what it is supposed to do – sweeping slowly back and forth. But when I push the “A” button again, nothing happens if I push the button while the servo is executing a sweep. If I am lucky enough to push the “A” button at its start position (presumably when the program returns to main) it will toggle and stop rotation. But this is very iffy and I can catch it maybe once every ten tries. The idea is to be able to toggle B.7/ C.7 while the servo is executing a sweep. (see lines 75 and 82)
The strange thing is that the program seems to work as it should when I run it in the simulator.
View attachment Wiring Diagram 3.1.PDF
Any thoughts or suggestions would be most appreciated.
Also attached is the wiring diagram.
However, here is what is happening. When powered up, the board is in “manual” mode by default. When I press the “B” and “D” buttons, the servo initializes but then does not move while I keep the button pressed. I can alternate pushing the buttons, but all it does is initializes the servo to its start position. Note: the receiver output goes high when the corresponding button on the transmitter is pressed.
Even more vexing is what happens when I try to toggle back and forth between “auto” and “manual”. The first push on button “A” takes me into “auto” mode and the servo does what it is supposed to do – sweeping slowly back and forth. But when I push the “A” button again, nothing happens if I push the button while the servo is executing a sweep. If I am lucky enough to push the “A” button at its start position (presumably when the program returns to main) it will toggle and stop rotation. But this is very iffy and I can catch it maybe once every ten tries. The idea is to be able to toggle B.7/ C.7 while the servo is executing a sweep. (see lines 75 and 82)
The strange thing is that the program seems to work as it should when I run it in the simulator.
Code:
'******************18M2 sentinel.bas****************
'Version 1.2
'AJZ/August 2015
'This is code for the Super Sentinel using the CHI030A
'PICAXE 18 standard project board
'The sentinel is controlled by a 4 channel transmitter/receiver
'When the Channel button on the transmitter is pressed,
'the corresponding channel on the receiver goes high
'Channel A toggles the turret between auto & manual mode
'Channel D drives the turret left
'Channel B drives the turret right
'Channel C fires the gun
'turret rotation is made using a standard servo
'In addition the sound of an alien recording is played during rotation
'===Constants===
symbol abit = 500 'sets short pause interval
symbol atic = 30 'sets servo pause to limit servo speed
'===Variables===
Symbol Chan_A = pinC.2 'Assign receiver channel A to Port C.2
Symbol Chan_B = pinC.0 'Assign receiver channel B to Port C.0
Symbol Chan_C = pinC.6 'Assign receiver channel C to Port C.6
Symbol Chan_D = pinC.1 'Assign receiver channel D to Port C.1
Symbol slave = pinC.7 'Assign auto-rotate latch to Port C.0
'pin B.7 & C.7 are jumpered together
symbol motor = B.0 'output to servo
symbol master = B.7 'toggles auto mode on & off
symbol LED = B.1 'fires LED
symbol beep = B.3 'makes "alien recording" noise
symbol chirp = B.2 'makes "strange alien" noise
symbol gun = B.4 'makes "alien machine gun" noise
'===Directives===
#com 1 'specify serial port
#picaxe 18M2 'specify processor
'#no_data 'save download time
'#terminal of 'disable terminal window
'============== Begin Main Program ==========================
dirsB = %11111111 'all outputs
dirsC = %00000000 'all inputs
main:
If Chan_A = 1 then 'press "A" on xmtr
toggle master 'toggles outpin B.1 between Hi/Lo
end if
pause atic
If slave = 1 then 'jumper between B.7 & C.7
gosub auto
end if
if Chan_D = 1 then 'press "D" on xmtr
gosub manleft 'manually rotate turret left
end if
If Chan_B = 1 then 'press "B" on xmtr
gosub manright 'manually rotate turret right
end if
If Chan_C = 1 then 'Chan "C" button is pressed on xmtr
gosub shoot 'execute shoot sub-routine
end if
pause abit
goto main
auto:
high chirp 'activate "strange alien" sound
pause abit 'a momentary pulse activates
low chirp 'a 30 second sound bite
servo motor, 90 'pre-positions servo
pause abit '0.5 sec delay
for b1 = 90 to 210 'sets travel limits
servopos motor, b1 'sweeps servo left
pause atic 'controls servo speed
if Chan_A = 1 then 'press "A" on xmtr
return
end if
next b1 'until travel limit is reached
for b1 = 210 to 90 step -1 'reverses travel limits & direction
servopos motor,b1 'sweeps servo right
pause atic 'controls servo speed
if Chan_A = 1 then 'press "A" on xmtr
return
end if
next b1 'until travel limit is reached
return 'continue until B.1 is toggled
manleft:
high beep 'activate "alien recording" sound
pause abit 'a momentary pulse activates
low beep 'a 30 second sound bite
servo motor,90 'pre-positions servo
pause abit '0.5 sec delay
for b1 = 90 to 210 'sets travel limits & direction
servopos motor,b1 'pulses motor left
pause atic 'controls servo speed
if Chan_D = 0 then 'until button is released
goto main
end if
next b1 'or until travel limit is reached
pause abit
return
manright:
high beep 'activate "alien recording" sound
pause abit 'a momentary pulse activates
low beep 'a 30 second sound bite
servo motor,210 'pre-positions servo
pause abit '0.5 sec delay
for b1 = 210 to 90 step -1 'sets travel limits and direction
servopos motor,b1 'pulses motor right in increments
pause atic 'controls servo speed
if Chan_B = 0 then 'until button is released
goto main
end if
next b1 'or until limit is reached
pause abit
return
shoot:
high gun 'take pin B.4 high
pause 100 'a short pulse plays entire sound bite
low gun 'take pin B.4 low
for b0 = 1 to 3 'entire sound bite is about 3 seconds
high LED 'so we flash the LED at 0.5 sec intervals
pause abit
low LED
pause abit
next b0
return 'finished firing sequence
Any thoughts or suggestions would be most appreciated.
Also attached is the wiring diagram.