def main(): cap = MPR121() print("initializing system") say("initializing system") sleep(1) while True: for i in range(12): mpr.on_touch(i, lambda *x: print(x))
def main(): motion_detector = MotionDetector(24) # servo #5 on hat but = aiy.voicehat.get_button() print("initializing system") say("initializing system") sleep(1) while True: if motion_detector.watch() is True: say("STAY AWAY!")
def main(): dof = DOF.MPU9250() print("initializing system") say("initializing system") sleep(1) while True: a = dof.readAccel() g = dof.readGyro() m = dof.readMagnet() print(a) print(g) print(m) print("---------------------") sleep(0.25)
def main(): dof = DOF.MPU9250() print("initializing system") say("initializing system") sleep(1) while True: a = dof.readAccel() g = dof.readGyro() m = dof.readMagnet() print(a) print(g) print(m) if a['x'] < 0 or a['y'] < 0 or a['z'] < 0: print("dont rock the boat!") say("Hey dont rock the boat!") print("---------------------") sleep(0.25)
def main(): stream = StreamListener.createStream() stream.filter("Google Yahoo", async=True) # build a recognizer and load it up with terms rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('min') rec.expect_phrase('max') rec.expect_phrase('mid') # start listening aiy.audio.get_recorder().start() # setup servo 0 servo = Servo(26) # setup the button but = aiy.voicehat.get_button() # the led for the button led = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(led, GPIO.OUT) # one time init message printed to console and said through speaker print("initializing system") say("initializing system") sleep(1) # wait for one second while True: say("press button and say min, max or mid to control servo") GPIO.output(led, GPIO.HIGH) print("press button to command servo") but.wait_for_press() print("listening") text = rec.recognize() if text is None: GPIO.output(led, GPIO.LOW) say("That is not a valid command!") else: text = text.lower() GPIO.output(led, GPIO.HIGH) if 'min' in text: say("min") print("min") servo.min() elif 'max' in text: say("max") print("max") servo.max() elif 'mid' in text: say("mid") print("mid") servo.mid() else: say("i'm sorry i heard, " + text + " which is not a valid command") print("i'm sorry i heard, " + text + " which is not a valid command") GPIO.output(led, GPIO.LOW)
def on_status(self, tweet): if "google" in tweet.text.lower(): say("Google") elif "yahoo" in tweet.text.lower(): say("Yahoo")
def main(): rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('theature chase') rec.expect_phrase('max') rec.expect_phrase('mid') rec.expect_phrase('off') aiy.audio.get_recorder().start() but = aiy.voicehat.get_button() led = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(led, GPIO.OUT) pwm = PWM(4) print("initializing system") say("initializing system") sleep(1) while True: say("press button and say min, max or mid to contol the D C Motor") GPIO.output(led, GPIO.HIGH) print("press button to command servo") but.wait_for_press() print("listening") text = rec.recognize() if text is None: GPIO.output(led, GPIO.LOW) say("That is not a valid command!") else: text = text.lower() GPIO.output(led, GPIO.HIGH) if 'theature chase' in text: say("theature chase") theaterChase(strip, Color(127, 127, 127)) # White theater chase theaterChase(strip, Color(127, 0, 0)) # Red theater chase theaterChase(strip, Color(0, 0, 127)) # Blue theater chase elif 'color wipe' in text: say("color wipe") colorWipe(strip, Color(255, 0, 0)) # Red wipe colorWipe(strip, Color(0, 255, 0)) # Blue wipe colorWipe(strip, Color(0, 0, 255)) # Green wipe print("color wipe") pwm.value = 0.8 elif 'rainbow' in text: say("rainbow") print("rainbow") rainbow(strip) rainbowCycle(strip) theaterChaseRainbow(strip) else: pwm.value = 0.0 say("i'm sorry i heard, " + text + " which is not a valid command") print("i'm sorry i heard, " + text + " which is not a valid command") GPIO.output(led, GPIO.LOW)
def main(): rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('min') rec.expect_phrase('max') rec.expect_phrase('mid') rec.expect_phrase('percent') rec.expect_phrase('%') rec.expect_phrase('off') aiy.audio.get_recorder().start() led = aiy.voicehat.get_led() but = aiy.voicehat.get_button() pwm = PWM(4) led.set_state(aiy.voicehat.LED.ON) say("press button to control motor") led.set_state(aiy.voicehat.LED.BLINK) sleep(1) while True: print("press button for motor control") but.wait_for_press() led.set_state(aiy.voicehat.LED.ON) pwm.value = 0.0 print("How fast would you like the Motor to go?") say("How fast would you like the Motor to go?") led.set_state(aiy.voicehat.LED.BLINK) text = rec.recognize() if text is None: led.set_state(aiy.voicehat.LED.OFF) print("That is not a valid command!") say("That is not a valid command!") else: text = text.lower() led.set_state(aiy.voicehat.LED.ON) if 'min' in text: print("min") say("min") pwm.value = 0.2 led.set_state(aiy.voicehat.LED.OFF) elif 'max' in text: print("max") say("max") pwm.value = 0.8 led.set_state(aiy.voicehat.LED.OFF) elif 'mid' in text: print("mid") say("mid") pwm.value = 0.4 led.set_state(aiy.voicehat.LED.OFF) elif 'off' in text: print("off") say("off") pwm.value = 0.0 led.set_state(aiy.voicehat.LED.BLINK) elif 'percent' in text or '%' in text: p_list = list(filter(str.isdigit, text)) p = '' try: for dig in p_list: p += str(dig) p = int(p) except ValueError: p = -1 pass except AttributeError: p = -1 pass if p >= 0 and p <= 100: print("setting motor to : ", p * 0.01) say(str(p) + " percent") pwm.value = p * 0.01 led.set_state(aiy.voicehat.LED.OFF) else: print("I am sorry I can only accept a percent between 0 and 100") say("I am sorry I can only accept a percent between 0 and 100") led.set_state(aiy.voicehat.LED.BLINK) else: pwm.value = 0.0 print("i'm sorry i heard, " + text + " which is not a valid command") say("i'm sorry i heard, " + text + " which is not a valid command") print("You can say things like: min, max, off. mid, 45 percent and 91" + " percent.") say("You can say things like: min, max, off. mid, 45 percent and 91" + " percent.") led.set_state(aiy.voicehat.LED.BLINK)
def main(): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase("french") recognizer.expect_phrase("spanish") recognizer.expect_phrase("german") recognizer.expect_phrase("english") recognizer.expect_phrase("italian") current_lang = "en-US" button = aiy.voicehat.get_button() led = aiy.voicehat.get_led() aiy.audio.get_recorder().start() led.set_state(aiy.voicehat.LED.ON) print("-------------------------------------------") print("please ask me to translate into English, Franch, German, Italian, or Spanish") r = random(1,3) if r == 1: aiy.audio.say("I speak many languages, test me out.") elif r == 2: aiy.audio.say("Welcome to the translation box, lets learn!.") elif r == 3: aiy.audio.say("Translation box initializing: English") while True: print('Press the button and speak') led.set_state(aiy.voicehat.LED.BLINK) button.wait_for_press() print('Listening...') led.set_state(aiy.voicehat.LED.ON) text = recognizer.recognize() if text is not None: led.set_state(aiy.voicehat.LED.OFF) text = text.lower() print(text) if "french" in text: print("translating to french") say("translating to french") current_lang = 'fr-FR' elif "german" in text: print("translating to German") say("translating to German") current_lang = 'de-DE' elif "english" in text: print("translating to English") say("translating to English") current_lang = 'en-US' elif "italian" in text: print("translating to Italian") say("translating to Italian") current_lang = 'it-IT' elif "spanish" in text: print("translating to Spanish") say("translating to Spanish") current_lang = 'es-ES' else: aiy.i18n.set_language_code(current_lang) print(text) say(text) aiy.i18n.set_language_code("en-US") else: print("I am sorry, I did not understand") say("I am sorry I did not understand")
def main(): rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('min') rec.expect_phrase('max') rec.expect_phrase('mid') rec.expect_phrase('off') aiy.audio.get_recorder().start() but = aiy.voicehat.get_button() led = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(led, GPIO.OUT) pwm = PWM(4) print("initializing system") say("initializing system") sleep(1) while True: say("press button and say min, max or mid to contol the D C Motor") print("press button and min, max or mid to contol the D C Motor") GPIO.output(led, GPIO.HIGH) print("press button to command servo") but.wait_for_press() print("listening") text = rec.recognize() if text is None: GPIO.output(led, GPIO.LOW) say("That is not a valid command!") else: text = text.lower() GPIO.output(led, GPIO.HIGH) if 'min' in text: say("min") print("min") pwm.value = 0.2 elif 'max' in text: say("max") print("max") pwm.value = 0.8 elif 'mid' in text: say("mid") print("mid") pwm.value = 0.4 elif 'off' in text: say("off") print("off") pwm.value = 0.0 else: pwm.value = 0.0 say("i'm sorry i heard, " + text + " which is not a valid command") print("i'm sorry i heard, " + text + " which is not a valid command") GPIO.output(led, GPIO.LOW)