Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- # python script to register an interrupt that will monitor for when a coin is entered and will process the 'coin' function by emulating a key press which is mapped in MAME
- #sends the C and D keys one after the next. C and D are mapped to Coin1 and Coin2 so each actual coin entered allows for a two player game
- import RPi.GPIO as GPIO
- import logging
- import datetime
- import time
- from evdev import UInput, ecodes as e
- verbose=False
- ui=UInput()
- logging.basicConfig(filename='/home/pi/coin.log',level=logging.DEBUG)
- def my_callback(channel):
- logging.debug('Coin Inserted at %s',datetime.datetime.now())
- if (verbose):
- print "\nCoin"
- ui.write(e.EV_KEY, e.KEY_C, 1)
- ui.syn()
- time.sleep(0.10)
- ui.write(e.EV_KEY, e.KEY_C, 0)
- ui.syn()
- time.sleep(0.10)
- ui.write(e.EV_KEY, e.KEY_D, 1)
- ui.syn()
- time.sleep(0.10)
- ui.write(e.EV_KEY, e.KEY_D, 0)
- ui.syn()
- try:
- GPIO.setmode(GPIO.BCM)
- # GPIO 21 set up as an input, pulled up (normally closed circuit), connected to 3V3 on coin input from accepter machine
- GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.add_event_detect(21, GPIO.FALLING, callback=my_callback)
- while (True):
- wait = True
- finally:
- ui.close()
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement