A TF2 Mini Sentry

Blargenth

New Member
So here's my final post for the time. I made a lot of sacrifices to get this project off of the ground and to make a good show at the convention..... and it broke 5 minutes into the actual panel. The connector I hot glued to the frame broke when I tried to move the whole assembly and made the whole project useless.

Ontop of that, the night before something shorted in the 12v power plug for the amplifier and started smoking, and I didn't bring a spare so their was no audio either. I never managed to get the LED to work at all, and the test code that I used from Bertz which allowed me to show what inputs were working through binary, only returned the pin5 as a working input. So I probably either damaged the receiver when it was shorting, or I wired it wrong.

So it was a learning experience sure, but it was also a complete bust.... I'll hang on to the parts and try it again some day, maybe fore the biannual gaming party on campus, but probably not any thing any time soon.
 

techElder

Well-known member
“If you fail to plan, you are planning to fail!”

― Benjamin Franklin
Start planning now while the failures are fresh on your mind. Failures are just obvious learning experiences. I still remember the first tech speech I made many years ago. No one told me the microphone was off.
 

erco

Senior Member
Bummer, Blargenth, you got very close. Kudos for a lot of effort in a short time. Per Tex, get right back up on that horse when your schedule permits. We're here to help.
 

AlbertZ

Senior Member
I was helping the O.P. with this project and was disappointed to see him give up after all the hard work he put into it. Perhaps he will look in on this forum and be re-energized based on what I am about to put forward. I really feel bad because we went away on holidays just as his project was nearing conclusion. I was intrigued by this project and would like to replicate it with a few differences. The O.P. was using an 18M2 project board based on my suggestion, in order to keep his costs down. I will be using a Picaxe 28X2 shield base and the instant robot shield (AXE408) that was used on another project. The O.P. also used a servo which he salvaged from an old RC car to rotate the turret. I will be using a GM3 gear motor because I have several lying around.

With that having been said, let’s review what we want this puppy to do. On power up we would like the turret to rotate back and forth while emitting a weird alien sound.

Upon pressing one of the buttons on the transmitter, the turret will go into a manual mode and drive in the direction assigned to the button (right or left). So, two of the buttons on the transmitter will drive the turret right or left as desired. A third button will be used to fire the gun which consists of flashing an LED and emitting an alien gun sound.

If no commands are received from the transmitter after a suitable delay (TBD) the turret will revert back to auto mode (rotate back and forth on its own).
I have worked out the code for each of these functions and tested them on the simulator. However, I am stumped how to integrate this all into one program. Can I use the fourth button on the transmitter to latch auto mode on and off? Is the use of interrupts appropriate here? If so I don’t have a clue since I never used them before. Or perhaps the case construct would be more appropriate? As I said, I’m stumped right now. Any suggestions would be appreciated as well as some code snippets to get me going in the right direction would be great! Also attached is an I/O table with pin assignments and labels.

Here is what I have done so far. The first code snippet lists all the declarations and is the code for automatic turret rotation.


Code:
'******************Auto Turret.bas****************
'Version 1.1
'AJZ/July 2015
'This is code for the Super Sentinel using the AXE401 shield base
'and the AXE408 instant robot shield
'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 drives the turret left
'Channel B drives the turret right
'the limit of rotation is determined by Hall effect sensors
'motor is GM3 or equivalent, 5 volt 3 RPM
'When the power is applied to the shield, the turret rotates back and forth
'In addition the sound of an alien recording is played during rotation

'===Constants===

symbol atad = 2000		'sets long pause interval
symbol abit = 500			'sets short pause interval

'===Variables===
Symbol Chan_A = pinA.0		'Assign receiver channel A to Port A.0
Symbol Chan_B = pinA.1		'Assign receiver channel B to Port A.1
Symbol Chan_C = pinA.2		'Assign receiver channel C to Port A.2
Symbol Chan_D = pinA.3		'Assign receiver channel D to Port A.3
Symbol Limit_L = pinB.3		'Assign left travel limit to Port B.3
Symbol Limit_R = pinB.4		'Assign right travel limit to Port B.4

symbol motcont  = C.1	      'motor ON/OFF
symbol motdir   = C.0		'determines motor direction HI/LO
symbol LED      = C.4	      'fires LED
symbol beep     = C.6	      'makes "alien recording" noise	
symbol chirp    = C.7    	'makes "strange alien" noise
symbol gun      = B.2         'makes "alien machine gun" noise

'===Directives===
#com 3				'specify serial port
#picaxe 28X2			'specify processor
'#no_data				'save download time
'#terminal of			'disable terminal window

'============== Begin Main Program ==========================
dirsA = %00000000			'all inputs
dirsB = %11100111			'B.3 & B.4 are inputs
dirsC = %11111111			'all outputs

auto:
high beep				'activate "strange alien" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
if Limit_L = 1 and Limit_R = 1 then	'turret is out of the limits
gosub left				'rotate turret left
end if
If Limit_L = 0 then		'turret is in left limit
	pause abit
	gosub right			'rotate turret right
end if
If Limit_R = 0 then		'turret is in right limit
	pause abit
	gosub left			'rotate turret left
end if
goto auto

left:
high motcont : high motdir	'high C.1 & C.0 go left
do until Limit_L = 0		'until limit made
	loop
low motcont				'low C.1 stops motor
pause abit
return

right:
high motcont : low motdir	'high C.1 low C.0 go right
do until Limit_R = 0		'until limit made
	loop
low motcont				'stop motor
pause abit
return
This next code snippet is for manual rotation of the turret.
Code:
'============== Begin manual turret Program ==========================
dirsA = %00000000			'all inputs
dirsB = %11100111			'B.3 & B.4 are inputs
dirsC = %11111111			'all outputs

main:
if Chan_A = 1 then		'press "A" on xmtr
gosub manleft				'rotate turret left
end if
If Chan_B = 1 then		'press "B" on xmtr
gosub manright				'rotate turret right
end if
goto main

manleft:
high beep				'activate "alien recording" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
high motcont : high motdir	'high C.1 & C.0 go left
if Chan_A = 0 or Limit_L = 0 then	'button released or limit made
	low motcont			'stop motor
end if
do until Limit_L = 0		'until limit made
	loop
low motcont				'low C.1 stops motor
pause abit
return

manright:
high beep				'activate "alien recording" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
high motcont : low motdir	'high C.1 low C.0 go right
if Chan_B = 0 or Limit_R = 0 then	'button released or limit made
	low motcont			'stop motor
end if
do until Limit_R = 0		'until limit made
	loop
low motcont				'stop motor
pause abit
return
Finally this last code snippet fires the gun.
Code:
'============== Begin gun Program ==========================
dirsA = %00000000			'all inputs
dirsB = %11100111			'B.3 & B.4 are inputs
dirsC = %11111111			'all outputs

main:
If Chan_D = 1 then		'Chan A button is pressed on xmtr
	gosub shoot    		'execute shoot sub-routine
end if
goto main

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
View attachment Super Sentinel I-O.pdf
 

Rick100

Senior Member
Hello Albert,

I saw your post earlier but haven't had time time to respond until now because of work. I provided some code in post 37 for the OP that works with a servo. The program works by using a main task that responds to input from the remote and a subroutine that sweeps the servo back and forth. In the main part, a loop counter called idleCount is reset to zero when any input is received from the remote. Each time through the loop with no input will increment the counter. If it exceeds the value represented by IDLE_TRIGGER the sweep subroutine is called. The sweep subroutine is exited when any input is received from the receiver.

I used that method on the following program that works with a dc motor. I left out most of the sound stuff. I tried it in the simulator but can't guarantee anything. With limit switches, user inputs, and motor controls, I could have easily missed something.

Code:
[color=Green]'===Constants===[/color]

[color=Blue]symbol atad [/color][color=DarkCyan]= [/color][color=Navy]2000            [/color][color=Green]'sets long pause interval[/color]
[color=Blue]symbol abit [/color][color=DarkCyan]= [/color][color=Navy]500             [/color][color=Green]'sets short pause interval[/color]

[color=Blue]symbol IDLE_TRIGGER [/color][color=DarkCyan]= [/color][color=Navy]400     [/color][color=Green]'loop count trigger for entering idle mode

'===Variables===[/color]
[color=Blue]Symbol [/color][color=Purple]Chan_A [/color][color=DarkCyan]= [/color][color=Purple]pinA.0        [/color][color=Green]'Assign receiver channel A to Port A.0[/color]
[color=Blue]Symbol [/color][color=Purple]Chan_B [/color][color=DarkCyan]= [/color][color=Purple]pinA.1        [/color][color=Green]'Assign receiver channel B to Port A.1[/color]
[color=Blue]Symbol [/color][color=Purple]Chan_C [/color][color=DarkCyan]= [/color][color=Purple]pinA.2        [/color][color=Green]'Assign receiver channel C to Port A.2[/color]
[color=Blue]Symbol [/color][color=Purple]Chan_D [/color][color=DarkCyan]= [/color][color=Purple]pinA.3        [/color][color=Green]'Assign receiver channel D to Port A.3[/color]
[color=Blue]Symbol [/color][color=Purple]Limit_L [/color][color=DarkCyan]= [/color][color=Purple]pinB.3       [/color][color=Green]'Assign left travel limit to Port B.3[/color]
[color=Blue]Symbol [/color][color=Purple]Limit_R [/color][color=DarkCyan]= [/color][color=Purple]pinB.4       [/color][color=Green]'Assign right travel limit to Port B.4[/color]

[color=Blue]symbol motcont  [/color][color=DarkCyan]= [/color][color=Blue]C.1         [/color][color=Green]'motor ON/OFF[/color]
[color=Blue]symbol motdir   [/color][color=DarkCyan]= [/color][color=Blue]C.0         [/color][color=Green]'determines motor direction HI/LO[/color]
[color=Blue]symbol LED      [/color][color=DarkCyan]= [/color][color=Blue]C.4         [/color][color=Green]'fires LED[/color]
[color=Blue]symbol beep     [/color][color=DarkCyan]= [/color][color=Blue]C.6         [/color][color=Green]'makes "alien recording" noise      [/color]
[color=Blue]symbol chirp    [/color][color=DarkCyan]= [/color][color=Blue]C.7         [/color][color=Green]'makes "strange alien" noise[/color]
[color=Blue]symbol gun      [/color][color=DarkCyan]= [/color][color=Blue]B.2         [/color][color=Green]'makes "alien machine gun" noise[/color]

[color=Blue]symbol [/color][color=Purple]currentDir [/color][color=DarkCyan]= [/color][color=Purple]bit8      [/color][color=Green]' 0 = right / 1 = left[/color]
[color=Blue]symbol [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Purple]w27[/color]

[color=Green]'===Directives===[/color]

[color=Navy]#picaxe [/color][color=Black]28X2                  [/color][color=Green]'specify processor[/color]



[color=Purple]dirsA [/color][color=DarkCyan]= [/color][color=Navy]%00000000             [/color][color=Green]'all inputs[/color]
[color=Purple]dirsB [/color][color=DarkCyan]= [/color][color=Navy]%11100111             [/color][color=Green]'B.3 & B.4 are inputs[/color]
[color=Purple]dirsC [/color][color=DarkCyan]= [/color][color=Navy]%11111111             [/color][color=Green]'all outputs


      [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Black]main:
      [/color][color=Blue]if [/color][color=Purple]Chan_A [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=DarkCyan]and [/color][color=Purple]Limit_L [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then        [/color][color=Green]'press "A" on xmtr and not on left limit
            [/color][color=Blue]high motdir                         [/color][color=Green]'go left
            [/color][color=Blue]high motcont                        [/color][color=Green]'motor on
            [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Navy]0                       [/color][color=Green]'reset on activity
      [/color][color=Blue]elseif [/color][color=Purple]Chan_B [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=DarkCyan]and [/color][color=Purple]Limit_R [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then          [/color][color=Green]'press "B" on xmtr and not on right limit
            [/color][color=Blue]low motdir                          [/color][color=Green]'go right
            [/color][color=Blue]high motcont                        [/color][color=Green]'motor on
            [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Navy]0                       [/color][color=Green]'reset on activity
      [/color][color=Blue]elseif [/color][color=Purple]Chan_D [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
            low motcont                         [/color][color=Green]'motor off
            [/color][color=Blue]gosub [/color][color=Black]shoot
            [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]else
            low motcont                         [/color][color=Green]'motor off
            [/color][color=Blue]inc [/color][color=Purple]idleCount                       [/color][color=Green]'increment on inactivity
      [/color][color=Blue]endif

      if [/color][color=Purple]idleCount [/color][color=DarkCyan]> [/color][color=Blue]IDLE_TRIGGER then 
            gosub [/color][color=Black]auto
            [/color][color=Purple]idleCount [/color][color=DarkCyan]= [/color][color=Navy]0                       [/color][color=Green]'returned from the auto subroutine so reset the counter
      [/color][color=Blue]endif

      goto [/color][color=Black]main

auto:
      [/color][color=Purple]currentDir [/color][color=DarkCyan]= [/color][color=Purple]Limit_L                            [/color][color=Green]'initial direction
      
      [/color][color=Blue]do
            if [/color][color=Purple]currentDir [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=DarkCyan]and [/color][color=Purple]Limit_L [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then    [/color][color=Green]'press "A" on xmtr and not on left limit
                  [/color][color=Blue]high motdir                         [/color][color=Green]'go left
                  [/color][color=Blue]high motcont                        [/color][color=Green]'motor on
            [/color][color=Blue]elseif [/color][color=Purple]currentDir [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]Limit_R [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then            [/color][color=Green]'press "B" on xmtr and not on right limit
                  [/color][color=Blue]low motdir                          [/color][color=Green]'go right
                  [/color][color=Blue]high motcont                        [/color][color=Green]'motor on
            [/color][color=Blue]else
                  [/color][color=Purple]currentDir [/color][color=DarkCyan]= not [/color][color=Purple]currentDir         [/color][color=Green]'invert bit
            [/color][color=Blue]endif
      
      loop while [/color][color=Purple]Chan_A [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]Chan_B [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=DarkCyan]and [/color][color=Purple]Chan_C [/color][color=DarkCyan]= [/color][color=Navy]0   [/color][color=Green]'stay in loop until input from receiver

      [/color][color=Blue]low motcont                                     [/color][color=Green]'motor off
      
      [/color][color=Blue]return[/color]

[color=Black]shoot:
      [/color][color=Blue]high gun                      [/color][color=Green]'take pin B.4 high
      [/color][color=Blue]pause [/color][color=Navy]100                     [/color][color=Green]'a short pulse plays entire sound bite
      [/color][color=Blue]low gun                       [/color][color=Green]'take pin B.4 low
      
      [/color][color=Blue]for [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]3               [/color][color=Green]'entire sound bite is about 3 seconds
            [/color][color=Blue]high LED                [/color][color=Green]'so we flash the LED at 0.5 sec intervals
            [/color][color=Blue]pause abit
            low LED
            pause abit
      next [/color][color=Purple]b0
      [/color][color=Blue]return                        [/color][color=Green]'finished firing sequence
      [/color]
Good luck,
Rick
 

AlbertZ

Senior Member
Thanks Rick,

Can always count on you for some really good input. Meanwhile during the middle of the night an idea occurred to me. We have four channels available to us with the RF gear the OP is using. Why not use one of the channels to toggle an output ON and OFF. Then jumper that channel to an input pin. Now we have four sub-routines available to us:

Channel A - toggles auto rotate on and off
Channel B - rotates turret left
Channel C - fires gun
Channel D - rotates turret right

Let's see how this works out in code using a motor and limit switches (Hall sensors) and a 28X2 processor.

Code:
'******************Sentinel Code.bas****************
'Version 2.0
'AJZ/July 2015
'This is code for the Super Sentinel using the AXE401 shield base
'and the AXE408 instant robot shield
'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
'the limit of rotation is determined by Hall effect sensors
'motor is GM3 or equivalent, 5 volt 3 RPM
'In addition the sound of an alien recording is played during rotation

'===Constants===
symbol abit = 500			'sets short pause interval

'===Variables===
Symbol Chan_A = pinA.0		'Assign receiver channel A to Port A.0
Symbol Chan_B = pinA.1		'Assign receiver channel B to Port A.1
Symbol Chan_C = pinA.2		'Assign receiver channel C to Port A.2
Symbol Chan_D = pinA.3		'Assign receiver channel D to Port A.3
Symbol Limit_L = pinB.3		'Assign left travel limit to Port B.3
Symbol Limit_R = pinB.4		'Assign right travel limit to Port B.4
Symbol slave   = pinB.6		'Assign auto-rotate latch to Port B.6
					'B.5 & B.6 are jumpered together

symbol motcont  = C.1	      'motor ON/OFF
symbol motdir   = C.0		'determines motor direction HI/LO
symbol LED      = C.4	      'fires LED
symbol beep     = B.2	      'makes "alien recording" noise	
symbol chirp    = B.0    	'makes "strange alien" noise
symbol gun      = B.1         'makes "alien machine gun" noise
symbol master   = B.5		'toggles auto mode on & off

'===Directives===
#com 3				'specify serial port
#picaxe 28X2			'specify processor
'#no_data				'save download time
'#terminal of			'disable terminal window

'============== Begin Main Program ==========================
dirsA = %00000000			'all inputs
dirsB = %10100111			'B.3, B.4 & B.6 are inputs
dirsC = %11111111			'all outputs

main:
If Chan_A = 1 then		'press "A" on xmtr
	toggle master		'toggles outpin B.5 between Hi/Lo
end if
If slave = 1 then			'jumper between B.5 & B.6
	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 beep				'activate "strange alien" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
if Limit_L = 1 and Limit_R = 1 then	'turret is out of the limits
gosub autoleft			'rotate turret left
end if
If Limit_L = 0 then		'turret is in left limit
	pause abit
	gosub autoright		'rotate turret right
end if
If Limit_R = 0 then		'turret is in right limit
	pause abit
	gosub autoleft		'rotate turret left
end if
goto main

autoleft:
high motcont : high motdir	'high C.1 & C.0 go left
do until Limit_L = 0		'until limit made
	loop
low motcont				'low C.1 stops motor
pause abit
return

autoright:
high motcont : low motdir	'high C.1 low C.0 go right
do until Limit_R = 0		'until limit made
	loop
low motcont				'stop motor
pause abit
return

manleft:
high beep				'activate "alien recording" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
high motcont : high motdir	'high C.1 & C.0 go left
if Chan_D = 0 or Limit_L = 0 then	'button released or limit made
	low motcont			'stop motor
end if
do until Limit_L = 0		'until limit made
	loop
low motcont				'low C.1 stops motor
pause abit
return

manright:
high beep				'activate "alien recording" sound
pause abit				'a momentary pulse activates
low beep				'a 30 second sound bite
high motcont : low motdir	'high C.1 low C.0 go right
if Chan_B = 0 or Limit_R = 0 then	'button released or limit made
	low motcont			'stop motor
end if
do until Limit_R = 0		'until limit made
	loop
low motcont				'stop motor
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
I am also putting together a working model of what the OP proposed using an 18M2 and servo which I hope to post very soon.
 

AlbertZ

Senior Member
Here is the code for a setup using an 18M2 project board and servo exactly as the OP was using on his setup. It seems to me this should work but I have not been able to successfully simulate it. The editor wont let me alter the state of input pin C.4 although it works for input pin C.2.

One other question about the 'toggle' command. I am using it to toggle output pin B.1, then using a wire jumper connecting B.1 to input pin C.0. Is this valid or will it cause other problems not readily discernible in the simulator?

The code for manual operation is a bit clunky but seems to work. Any suggestions welcome.

Code:
'******************18M2 sentinel.bas****************
'Version 1.0
'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.1		'Assign receiver channel A to Port C.1
Symbol Chan_B = pinC.2		'Assign receiver channel B to Port C.2
Symbol Chan_C = pinC.3		'Assign receiver channel C to Port C.3
Symbol Chan_D = pinC.4		'Assign receiver channel D to Port C.4
Symbol slave  = pinC.0		'Assign auto-rotate latch to Port C.0
					'B.1 & C.0 are jumpered together

symbol motor    = B.0	      'output to servo
symbol master   = B.1		'toggles auto mode on & off
symbol LED      = B.5	      '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 3				'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
If slave = 1 then			'jumper between B.1 & C.0
	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 beep				'activate "strange alien" 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
servopos motor, b1		'sweeps servo left
pause atic				'controls servo speed
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
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
 
Top