A pistol hammer/firing pin logic problem, i keep getting confused.
robdeadtech
Posts: 3
Greetings all,
I'm trying to detect the state of a "pistol" with a bs2 (not a bs2p) and I keep getting my logic confused and wondering if i could get some thoughts from the forum on a problem that keeps making my head hurt... heh. NOTE: I'm not doing this with a real gun, just a toy gun. I might be slow on logic, but I'm not crazy! ha. I'd like to detect when the hammer hits the "firing pin" by lighting a LED for about 2 seconds and then turning off.
I got to thinking this is a different thing than a momentary switch commonly found in arcade game pistols or a push-on push-off type switch like in a lamp.
The problem with a authentic hammer/firing pin type gun is when the hammer is down it means one of two things - the gun is firing RIGHT NOW or it has already been fired. Two very different things! heh.
So its seems what dictates whether the gun is firing or if the event has already happened is what state the hammer was in just before its in the state its in now. If the hammer was not down that mean it just fired. If it was already down, that means its already fired and is at rest.
A gun has a few states in my mind.
1. hammer is up (aka cocked back) - I'm calling this the "armed" state.
2. hammer is down, its in the "unarmed" state OR it means the gun is firing right now!
So it seems i want to detect armed or unarmed state first.
If in "armed" state, I want to loop to check for "unarmed" state.
if I go into unarmed state the gun is firing now!, turn on a LED to indicate a "shot".
Now wait until I go back into "armed" state when the hammer comes back otherwise keep checking.
So... I'm having trouble getting my head around if this is nested loops or an if, then, etc...
thanks much!
- Rob
Note: I'm not concerned about whether the toy gun is "loaded" or anything. its just a toy so, you know... the clip is always full.
Post Edited (robdeadtech) : 9/11/2007 5:31:02 AM GMT
I'm trying to detect the state of a "pistol" with a bs2 (not a bs2p) and I keep getting my logic confused and wondering if i could get some thoughts from the forum on a problem that keeps making my head hurt... heh. NOTE: I'm not doing this with a real gun, just a toy gun. I might be slow on logic, but I'm not crazy! ha. I'd like to detect when the hammer hits the "firing pin" by lighting a LED for about 2 seconds and then turning off.
I got to thinking this is a different thing than a momentary switch commonly found in arcade game pistols or a push-on push-off type switch like in a lamp.
The problem with a authentic hammer/firing pin type gun is when the hammer is down it means one of two things - the gun is firing RIGHT NOW or it has already been fired. Two very different things! heh.
So its seems what dictates whether the gun is firing or if the event has already happened is what state the hammer was in just before its in the state its in now. If the hammer was not down that mean it just fired. If it was already down, that means its already fired and is at rest.
A gun has a few states in my mind.
1. hammer is up (aka cocked back) - I'm calling this the "armed" state.
2. hammer is down, its in the "unarmed" state OR it means the gun is firing right now!
So it seems i want to detect armed or unarmed state first.
If in "armed" state, I want to loop to check for "unarmed" state.
if I go into unarmed state the gun is firing now!, turn on a LED to indicate a "shot".
Now wait until I go back into "armed" state when the hammer comes back otherwise keep checking.
So... I'm having trouble getting my head around if this is nested loops or an if, then, etc...
thanks much!
- Rob
Note: I'm not concerned about whether the toy gun is "loaded" or anything. its just a toy so, you know... the clip is always full.
Post Edited (robdeadtech) : 9/11/2007 5:31:02 AM GMT
Comments
There would be one loop awaiting the hammer to be cocked, move on to another loop awaiting to be fired , move to a subroutine to light the led then go back to the begining. If you wanted to keep track of "bullets" include a counter in the subroutine.
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger Pierson
Senior Electronics Technicain
DTI Assoicates
This is what I came up with that works, but it seems kind of nasty - an awful lot of IF DO ELSE GOSUBs and GOTOs to do what I want.
I'll clean it up tomorrow but thought i would post it for laughs and let you know that your assistance at least got me this far.
Thanks again!
' {$STAMP BS2}
' {$PBASIC 2.5}
AckPin PIN 3
Unarmed CON 1
Armed CON 0
Initialize:
IF Ackpin = Armed THEN
DO
IF AckPin = Unarmed THEN GOSUB Fired 'gun goes BOOM and smoke rises from the barrel.
LOOP
ELSE
GOTO Initialize
ENDIF
Fired:
HIGH 14
PAUSE 2000
LOW 14
GOTO Initialize