def play(file): global __popen__ if __popen__ is not None: __popen__.wait() print("Playing '{0}'".format(file)) cmd = ['mpg123', '-q', file] if Platform.is_raspberrypi(): __popen__ = subprocess.Popen(cmd)
def say(sentence): global __popen__ if __popen__ is not None: __popen__.wait() print("Saying '{0}'".format(sentence)) cmd = ['mpg123', '-q', "http://translate.google.com/translate_tts?tl=en&q={0}".format(sentence)] if Platform.is_raspberrypi(): __popen__ = subprocess.Popen(cmd)
def set_lamp(lamp_id, state): if Platform.is_raspberrypi() and lamp_id >= 0 and lamp_id < len(lamps): GPIO.output(lamps[lamp_id], state)
import time import Platform if Platform.is_raspberrypi(): import RPi.GPIO as GPIO # we have to use BCM mode to stay compatible with the dot3k GPIO.setmode(GPIO.BCM) lamps = [6, 13, 19, 26] if Platform.is_raspberrypi(): for lamp in lamps: GPIO.setup(lamp, GPIO.OUT) def set_lamp(lamp_id, state): if Platform.is_raspberrypi() and lamp_id >= 0 and lamp_id < len(lamps): GPIO.output(lamps[lamp_id], state) def all_off(): for lamp in range(0, len(lamps)): set_lamp(lamp, 0) def build_good(): set_lamp(0, 1) set_lamp(1, 1) set_lamp(2, 0) set_lamp(3, 0) def broken_test(): set_lamp(0, 0) set_lamp(1, 1)