Question about gun code for Xbrat

Hello,

I’m looking at adding the xbrat gun code to my hexapod. In doing so, I’ve stripped (from what I can tell) are all the elements needed to get it to work. I’m new to embedded programing and would like to get someone experienced to double check my thoughts/comments on each line and perhaps answer my questions.

;This sets the constants
RGUNP con p16
RGswP con p17
LGUNP con p18
LGswP con p19

;Set var type
RSwitch var bit
PrevRSW var bit
LSwitch var bit
PrevLSW var bit

;Not sure what in# represents, is this an input pin?
RSwitch = in17
LSwitch = in19

;set constant
BUTTON_DOWN con 0
BUTTON_UP con 1

;I shouldn’t need this if I’m not using a servo to move the gun?
if PrevRSW = 0 AND RSwitch = 1 then
hservo [RGUNP-7000\0]
else
PrevRSW = RSwitch
endif

;I shouldn’t need this if I’m not using a servo to move the gun (same as above)?
if PrevLSW = 0 AND LSwitch = 1 then
hservo [LGUNP-7000\0]
else
PrevLSW = LSwitch
endif

;Read incoming bits to perform some action
IF (DualShock(2).bit3 = 0) THEN ;R1 Button test
hservo [RGUNP\7000\0] ;Shouldn’t need this as it moves the servro, correct?
PrevRSW = BUTTON_UP ;Does this trigger to switch to fire?
ENDIF

IF (DualShock(2).bit2 = 0) THEN ;L1 Button test
hservo [LGUNP\7000\0] ;Same as above
PrevLSW = BUTTON_UP
ENDIF

After messing around with some code tonight, I guess what I’m really asking is how do you send a signal (or whatever it is in the embedded world) to trigger the switch!

I’m assuming its something like:

if(DualShock(2).bit6 = 0) then
Do something…
endif

I don’t know what that “do something” is! Are there functions that sends a pulse or do I define that?

I noticed in the hexapod code there is a reference to the var LastButton, I’m not sure what that does, example:

if(DualShock(2).bit6 = 0) and LastButton(1).bit6 then
Do something…
endif

Any thoughts are appreciated.

Thanks,

I believe your previous post had the way that Jim and James did it with their Brat.

To turn on the switch: hservo [RGUNP\7000\0] ;Shouldn’t need this as it moves the servro, correct?

To turn off the switch: hservo [RGUNP-7000\0]

The BattleSwitch or PicoSwitch as well as the new BasicMicro versions take a PWM signal to throw the switch. The BasicMicro switch has other methods as well…

If you are not using HSERVO in your program you can generate the signal using other commands like: servo, pwm, …

Kurt

Awesomesauce! That answers alot, I’ll mess around with them this evening.

Thank you for taking the time to answer.