Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import mod_utils
  2. import hardware.motor_hat
  3. # Example for adding custom code to the controller
  4.  
  5. from subprocess import Popen
  6.  
  7. module = None
  8.  
  9. def setup(robot_config):
  10. global module
  11. # Your custom setup code goes here
  12.  
  13.  
  14.  
  15. # Call the setup handler for max7219 LEDs
  16. hardware.motor_hat.setup(robot_config)
  17.  
  18. # This code calls the default setup function for your hardware.
  19. # global module
  20.  
  21. # module = __import__("hardware."+robot_config.get('robot', 'type'), fromlist=[robot_config.get('robot', 'type')])
  22. module = mod_utils.import_module('hardware', robot_config.get('robot', 'type'))
  23. module.setup(robot_config)
  24.  
  25. def move(args):
  26. # Your custom command interpreter code goes here
  27.  
  28. command = args['command']
  29. print "command recieved"
  30. print command
  31.  
  32. if args['key_position'] == 'up':
  33. if command == 'spaghetti':
  34. playSound('spaghetti.mp3')
  35. return
  36. elif command == 'directive':
  37. playSound('directive.mp3')
  38. return
  39. elif command == 'gasp':
  40. playSound('gasp.mp3')
  41. return
  42. elif command == 'adios':
  43. playSound('adios.mp3')
  44. return
  45. elif command == 'basghetti':
  46. playSound('basghetti.mp3')
  47. return
  48. elif command == 'does not compute':
  49. playSound('doesnotcompute.mp3')
  50. return
  51. elif command == 'yum':
  52. playSound('yum.mp3')
  53. return
  54. elif command == 'baby':
  55. playSound('baby.mp3')
  56. return
  57. elif command == 'response':
  58. playSound('response.mp3')
  59. return
  60. elif command == 'mom':
  61. playSound('mom.mp3')
  62. return
  63. elif command == 'neutralized':
  64. playSound('neutralized.mp3')
  65. return
  66.  
  67. # Call the command handler for max7219 LEDs
  68. #hardware.motor_hat.move(args)
  69.  
  70. # This code calls the default command interpreter function for your hardware.
  71. module.move(args)
  72.  
  73. def playSound ( fileName):
  74. Popen('/usr/bin/mpg123-alsa /home/pi/'+ fileName, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement