# Example of how to use the play sound function and change the base colour of Picoh. from picoh import picoh import random picoh.reset() picoh.wait(1) picoh.close() picoh.move(picoh.LIDBLINK, 0) picoh.setEyeShape('Heart') picoh.setEyeBrightness(0) picoh.playSound('fanfare', untilDone=False) picoh.wait(1.5) picoh.move(picoh.LIDBLINK, 5) picoh.setEyeBrightness(5) picoh.wait(1) picoh.move(picoh.LIDBLINK, 10) picoh.setEyeBrightness(10) picoh.wait(2) picoh.setEyeBrightness(7) picoh.wait(4) picoh.playSound('ohbot', untilDone=False) picoh.setEyeShape('Glasses') for x in range(0, 40): picoh.setBaseColour(random.randrange(0, 10), random.randrange(0, 10),
picoh.wait(1) # Move the HEADTURN and EYETURN to position 7. picoh.move(picoh.HEADTURN, 7) picoh.move(picoh.EYETURN, 7) # Set the base to red:3/10 green: 4/10 and blue 2/10. picoh.setBaseColour(3, 4, 2) picoh.wait(1) # Change the base to orange picoh.setBaseColour(10, 3, 0) # Set the eyeshape to SunGlasses picoh.setEyeShape("SunGlasses") # Slowly increase the brightness of Picoh's eyes. for x in range(0, 50): picoh.setEyeBrightness(x / 10) picoh.wait(0.2) # Get a random phrase from the speech database. phrase = picoh.getPhrase() picoh.say(phrase) # Wait a few seconds and then close. This detaches Picoh's motors. picoh.wait(3) picoh.close()
picoh.wait(1) picoh.setEyeShape("Eyeball") # initialize the client and wait to receive cloud-to-device message def iothub_client_sample_run(): try: client = iothub_client_init() message_listener_thread = threading.Thread(target=message_listener, args=(client, )) message_listener_thread.daemon = True message_listener_thread.start() while True: time.sleep(1000) except KeyboardInterrupt: print("IoTHubDeviceClient sample stopped") # main function if __name__ == '__main__': print("Starting the IoT Hub Python sample...") print("IoTHubDeviceClient waiting for commands, press Ctrl-C to exit") print("Reseting the PICOH") picoh.reset() picoh.say("The Picoh is alive") picoh.setEyeBrightness(5) iothub_client_sample_run()