Example #1
0
def xy(event):
    # Get the coordinates of where the mouse movement happened.
    xm, ym = event.x, event.y

    # Scale the coordniate so it is between 0-10. Divide by 60 as window is 600 x 600.
    xm = xm / 60
    ym = ym / 60

    # Use the scaled position to set Picoh's motor and pupil positions and base colour.
    picoh.move(picoh.HEADTURN, xm)
    picoh.move(picoh.HEADNOD, ym)
    picoh.move(picoh.EYETURN, xm)
    picoh.move(picoh.EYETILT, ym)
    picoh.baseColour(10 - ym, ym, xm)
Example #2
0
def message_listener(client):
    global RECEIVED_MESSAGES
    pythoncom.CoInitialize()  #fix to Picoh speech issue

    while True:
        message = client.receive_message()
        RECEIVED_MESSAGES += 1
        print("Message received")
        # print( "    Data: «{}»".format(message.data) )
        # print( "    Properties: {}".format(message.custom_properties))
        # print( "    Total calls received: {}".format(RECEIVED_MESSAGES))
        print(message.data.decode('utf-8'))

        picoh.say(message.data.decode('utf-8'))
        picoh.setEyeShape("Heart")
        picoh.move(picoh.HEADTURN, randint(3, 7))
        picoh.move(picoh.HEADNOD, randint(4, 7))
        picoh.baseColour(random() * 10, random() * 10, random() * 10)
        picoh.wait(1)
        picoh.setEyeShape("Eyeball")
Example #3
0
def handleInput():
    global moving
    while True:

        picoh.say("Hello picoh here, what shall I look up on wolfram alpha?")

        text = input("Question:\n")
        picoh.say(text)
        picoh.baseColour(10, 5, 0)

        # Stop the random movement.
        moving = False

        # Look forward and up.
        picoh.move(picoh.HEADTURN, 5)
        picoh.move(picoh.EYETILT, 7)
        picoh.move(picoh.HEADNOD, 9)

        # get a random phrase from set 2 in the speech database.
        picoh.say(picoh.getPhrase(set=2))

        # Try the call to a webservice to get a response from WolframAlpha.
        try:
            # Start random movement again
            moving = True
            res = wolfclient.query(text)
            ans = next(res.results).text

            # replace response text | with .
            ans = ans.replace("|", ".")
            picoh.say(ans)

            # set base to green.
            picoh.baseColour(0, 10, 0)

        # If no answer can be found then say answer not available and set base to red.
        except:
            print('Answer not available')
            picoh.say("Answer not available")
            picoh.baseColour(10, 0, 0)

        picoh.move(picoh.HEADTURN, 5)
Example #4
0
def handleInputWiki():
    global moving
    while True:

        picoh.say(
            "Hello picoh here, what would you like the wiki definition for?")

        # Put up a text box and wait for user to type the word they want to define.
        text = input("Define:\n")

        # Say the word they have typed.
        picoh.say(text)
        picoh.baseColour(10, 5, 0)

        # Stop the random movement
        moving = False

        # Look forward and up.
        picoh.move(picoh.HEADTURN, 5)
        picoh.move(picoh.EYETILT, 7)
        picoh.move(picoh.HEADNOD, 9)

        # get a random phrase from set 2 in the speech database.
        picoh.say(picoh.getPhrase(set=2))

        # Try the call to a webservice to get a response from Wikipedia.
        # Request the first sentence of the definition.
        try:
            # Start random movement again
            moving = True
            res = wikipedia.summary(text, sentences=1)
            picoh.say(res)
            picoh.baseColour(0, 10, 0)

        except:
            # If no answer can be found then say answer not available and set base to red.
            print('Answer not available')
            picoh.say("Answer not available")
            picoh.baseColour(10, 0, 0)
            picoh.move(picoh.HEADTURN, 5)
Example #5
0
# Say a phrase.
picoh.say("Hello my name is Picoh. Good to meet you")

# Move the HEADTURN and EYETURN to position 3.
picoh.move(picoh.HEADTURN, 3)
picoh.move(picoh.EYETURN, 3)

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.baseColour(3, 4, 2)

picoh.wait(1)

# Change the base to orange
picoh.baseColour(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.
Example #6
0
lastm = ""


# this is called on a separate thread to blink the eyes while running
def blinkLids():
    while (blinking):
        picoh.move(picoh.LIDBLINK, 0)
        sleep(0.2)
        picoh.move(picoh.LIDBLINK, 10)
        # wait for a random amount of time for realistic blinking
        sleep(randint(0, 4))


# start up sequence resets to mid position, sets the eyes to blue then goes to sleep
picoh.reset()
picoh.baseColour(0, 0, 10)
sleep(1.0)
picoh.baseColour(0, 0, 0)
picoh.move(picoh.HEADNOD, 0)
picoh.move(picoh.LIDBLINK, 0)
sleep(2.0)
# close to turn the motors off
picoh.close()

while (True):
    # get seconds and minutes into strings
    s = strftime("%S", localtime())
    m = strftime("%M", localtime())
    # set this to False for testing to make picoh speak continuously
    everyQuarterHour = True
    if ((everyQuarterHour == False) or
Example #7
0
blinking = False


#this is called on a separate thread to blink the eyes while running
def blinkLids():
    while (blinking):
        picoh.move(picoh.LIDBLINK, 0)
        sleep(0.2)
        picoh.move(picoh.LIDBLINK, 10)
        #wait for a random amount of time for realistic blinking
        sleep(randint(0, 4))


#start up sequence resets to mid position, sets the eyes to blue then goes to sleep
picoh.reset()
picoh.baseColour(0, 0, 10)
sleep(1.0)
picoh.baseColour(0, 0, 0)

# Start a thread for the blinking.
blinking = True
t = threading.Thread(target=blinkLids, args=())
t.start()

sleep(2.0)

picoh.say(
    "The picoh pi library now supports e speak meaning i can speak different languages and in different voices"
)

picoh.move(picoh.HEADTURN, 4)
Example #8
0
def cKey(event):
    picoh.say("Hello humans", untilDone=False)
    picoh.baseColour(3, 10, 3)
Example #9
0
def bKey(event):
    picoh.playSound('spring', untilDone=False)
    picoh.say("What's going on ?", untilDone=False)
    picoh.baseColour(10, 3, 3)
Example #10
0
def aKey(event):
    picoh.say("Hello I am Picoh", untilDone=False)
    picoh.baseColour(3, 3, 10)
Example #11
0
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.baseColour(random.randrange(0, 10), random.randrange(0, 10),
                     random.randrange(0, 10))
    picoh.wait(0.05)

picoh.baseColour(0, 0, 0)
picoh.wait(0.5)

picoh.setEyeShape('Angry')
picoh.playSound('smash', untilDone=False)
picoh.baseColour(10, 0, 0)

for x in range(0, 14):
    picoh.move(picoh.EYETILT, 3)
    picoh.wait(x / 100)
    picoh.move(picoh.EYETILT, 6)
    picoh.wait(x / 100)
Example #12
0
def baseCol():
    while True:
        # Set the base to a random rgb values between 0 and 10. 
        picoh.baseColour(random() * 10, random() * 10, random() * 10)
        # Wait between 10 and 20 seconds before changing again. 
        picoh.wait(randint(10, 20))