Created
June 14, 2019 02:57
-
-
Save RyAndrew/cf2eaa8f1f0762c7c3a1bcf0fa0e459d to your computer and use it in GitHub Desktop.
hardware_custom.py for custom sounds on letsrobot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mod_utils | |
import hardware.motor_hat | |
# Example for adding custom code to the controller | |
from subprocess import Popen | |
module = None | |
def setup(robot_config): | |
global module | |
# Your custom setup code goes here | |
# Call the setup handler for max7219 LEDs | |
hardware.motor_hat.setup(robot_config) | |
# This code calls the default setup function for your hardware. | |
# global module | |
# module = __import__("hardware."+robot_config.get('robot', 'type'), fromlist=[robot_config.get('robot', 'type')]) | |
module = mod_utils.import_module('hardware', robot_config.get('robot', 'type')) | |
module.setup(robot_config) | |
def move(args): | |
# Your custom command interpreter code goes here | |
command = args['command'] | |
print "command recieved" | |
print command | |
if args['key_position'] == 'up': | |
if command == 'spaghetti': | |
playSound('spaghetti.mp3') | |
return | |
elif command == 'directive': | |
playSound('directive.mp3') | |
return | |
elif command == 'gasp': | |
playSound('gasp.mp3') | |
return | |
elif command == 'adios': | |
playSound('adios.mp3') | |
return | |
elif command == 'basghetti': | |
playSound('basghetti.mp3') | |
return | |
elif command == 'does not compute': | |
playSound('doesnotcompute.mp3') | |
return | |
elif command == 'yum': | |
playSound('yum.mp3') | |
return | |
elif command == 'baby': | |
playSound('baby.mp3') | |
return | |
elif command == 'response': | |
playSound('response.mp3') | |
return | |
elif command == 'mom': | |
playSound('mom.mp3') | |
return | |
elif command == 'neutralized': | |
playSound('neutralized.mp3') | |
return | |
# Call the command handler for max7219 LEDs | |
#hardware.motor_hat.move(args) | |
# This code calls the default command interpreter function for your hardware. | |
module.move(args) | |
def playSound ( fileName): | |
Popen('/usr/bin/mpg123-alsa /home/pi/'+ fileName, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment