Shop OBEX P1 Docs P2 Docs Learn Events
A pistol hammer/firing pin logic problem, i keep getting confused. — Parallax Forums

A pistol hammer/firing pin logic problem, i keep getting confused.

robdeadtechrobdeadtech Posts: 3
edited 2007-09-12 04:42 in BASIC Stamp
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

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-09-11 05:38
    Hi Rob, how about on initialization the hammer is at rest and bridging a pair of wires that act as a switch. So the first part of the logic is saying· "I am at rest waiting to be armed" . When the hammer is cocked the logic moves on awaiting the next switch contact which·will mean·"I have been fired, light me up for 2 seconds". After which we return to the "I am at rest waiting to be armed"

    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 PiersonRoger Pierson Posts: 62
    edited 2007-09-11 16:00
    I think you can accomplish this with two loops that each check the status of the arm / unarmed switch. The first loop only calls the second after it detects the weapon has been armed. See the attached flowchart

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Roger Pierson
    Senior Electronics Technicain
    DTI Assoicates
    319 x 655 - 22K
  • robdeadtechrobdeadtech Posts: 3
    edited 2007-09-12 04:42
    ah! thanks Unasoundcode and Roger for the replies!

    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
Sign In or Register to comment.