Advertisement
Guest User

Untitled

a guest
Jun 1st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2. # 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
  3. #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
  4.  
  5. import RPi.GPIO as GPIO
  6. import logging
  7. import datetime
  8. import time
  9. from evdev import UInput, ecodes as e
  10.  
  11. verbose=False
  12. ui=UInput()
  13. logging.basicConfig(filename='/home/pi/coin.log',level=logging.DEBUG)
  14.  
  15. def my_callback(channel):
  16. logging.debug('Coin Inserted at %s',datetime.datetime.now())
  17. if (verbose):
  18. print "\nCoin"
  19. ui.write(e.EV_KEY, e.KEY_C, 1)
  20. ui.syn()
  21. time.sleep(0.10)
  22. ui.write(e.EV_KEY, e.KEY_C, 0)
  23. ui.syn()
  24. time.sleep(0.10)
  25. ui.write(e.EV_KEY, e.KEY_D, 1)
  26. ui.syn()
  27. time.sleep(0.10)
  28. ui.write(e.EV_KEY, e.KEY_D, 0)
  29. ui.syn()
  30.  
  31. try:
  32. GPIO.setmode(GPIO.BCM)
  33. # GPIO 21 set up as an input, pulled up (normally closed circuit), connected to 3V3 on coin input from accepter machine
  34. GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  35. GPIO.add_event_detect(21, GPIO.FALLING, callback=my_callback)
  36. while (True):
  37. wait = True
  38.  
  39. finally:
  40. ui.close()
  41. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement