Thought I'd share this.
I implemented a state machine turnstile (I prefer turnstYle but wth, no biggy....) based on what I read here
. The attached code is fully commented but in essence it takes care of these events: Current Event Transition New
Locked Coin Unlock Unlocked (normal operation)
Unlocked Pass Lock Locked (normal operation)
Locked Pass Alarm Locked (abnormal operation: forced entry)
Unlocked Coin Thanks Unlocked (abnormal operation: paid twice)
In a nutshell, it starts locked, you pay, it unlocks, you open, enter, close and it locks. If you pay once it's unlocked, thanks for the donation, you paid twice. If you open without paying, alarm.
My turnstile isn't mechanically correct: it's just a short metal strip on a hinge. One end rests on an electromagnet, and there's an optointerrupter half way along. The optoint detects the presence of the strip, the magnet locks it in place. Lifting the strip is like pushing into the turnstile, dropping it is like the stile closing behind you. You can lift the strip against the magnet to simulate an illegal entry.
Payment is by clicking a software debounced momentary switch, which simulates a coin drop.
This implementation does not worry about the stile being open, ie sort of hovering between "clicks"; perhaps PhaseII could look for that and alarm on a timeout, meaning someone is trapped or it didn't click closed properly.
You're welcome to do whatever you like with this.....