Exemplo n.º 1
0
# Car alarm
# The finch sounds an alarm, alternating high pitch sounds and
# flashing red abd blue lights, until its nose is turned up

from time import sleep
from lib.finch import Finch

finch = Finch()
x = 0
while x > -0.5:
    x, y, z, tap, shake = finch.acceleration()

    finch.led("#FF0000") # set the led to red
    finch.buzzer(1.0, 250)
    sleep(1.05)
    finch.led("#0000FF") # set the led to blue
    finch.buzzer(1.0, 400)
    sleep(1.05)

finch.halt()
finch.close()

Exemplo n.º 2
0
# A simple program that wanders and avoids obstacles

from lib.finch import Finch
from time import sleep

# Instantiate the Finch object and connect to Finch
tweety = Finch()

# Get the Z-Axis acceleration
zAccel = tweety.acceleration()[2]

# Do the following while the Finch is not upside down (z value in gees above -0.7)
while zAccel > -0.7:

    left_obstacle, right_obstacle = tweety.obstacle()
    # If there's an obstacle on the left, back up and arc
    if left_obstacle:
        tweety.led(255,0,0)
        tweety.wheels(-0.3,-1.0)
        sleep(1.0)
    # Back up and arc in the opposite direction if there's something on the right
    elif right_obstacle:
        tweety.led(255,255,0)
        tweety.wheels(-1.0, -0.3)
        sleep(1.0)
    # Else just go straight
    else:
        tweety.wheels(1.0, 1.0)
        tweety.led(0,255,0)
    # Keep reading in the Z acceleration
    zAccel = tweety.acceleration()[2]
Exemplo n.º 3
0
# A simple program that randomly changes the LED when the Finch is tapped or shaken
# Try it by setting the Finch on a table and tapping the top
from lib.finch import Finch
from random import randint

# Instantiate the Finch object and connect to Finch
tweety = Finch()

left, right = tweety.obstacle()

# Do the following while no obstacles are detected by Finch
while not left and not right:
    # Get the accelerations
    x, y, z, tap, shake = tweety.acceleration()

    # Print the acceleration data
    print("X is %.2f gees, Y is %.2f gees, Z is %.2f gees, tap is %r shake is %r" % (x, y, z, tap, shake));

    # If a tap or shake has been detected recently, set the LED to a random color
    if tap or shake:
        tweety.led(randint(0,255), randint(0, 255), randint(0,255))

    # Get obstacles to use to exit loop
    left, right = tweety.obstacle()

tweety.close()