Function InitCoinSlotChecker():
- Set LastCoinSlotState to the current state of the coin slot input (e.g., PORTBbits.RB4).
- Initialize Coins to 0.
Function Check4Coin():
- Initialize ReturnVal to false (indicates whether an event was detected).
- If the GameFSM is in the Idle state (QueryGameFSM() == Idle):
1. Read the current state of the coin slot into CurrentCoinSlotState (e.g., PORTBbits.RB4).
2. Get the current time using ES_Timer_GetTime(), and store it in CurrentTickCount.
**Coin Detection Logic:**
- If CurrentCoinSlotState == 0 (coin detected) and Coins < 1:
- Set ReturnVal to true (event detected).
- Increment Coins by 1.
- Update LastTickCount to the current time.
- Create a new event, ThisEvent, with EventType = COIN_INSERT.
- Post ThisEvent to the GameFSM using PostGameFSM().
**Reset Coin Counter:**
- If more than 300ms have passed since LastTickCount (CurrentTickCount - LastTickCount > 300):
- Reset Coins to 0.
- Update LastCoinSlotState to the current value of CurrentCoinSlotState.
- Return ReturnVal (indicates whether an event was posted).