forked from Amanda1223/Finch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtapExample.py
More file actions
26 lines (19 loc) · 878 Bytes
/
tapExample.py
File metadata and controls
26 lines (19 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 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()