HTML

tapExample.py

Nov 18th, 2016
159
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # A simple program that randomly changes the LED when the Finch is tapped or shaken
  2. # Try it by setting the Finch on a table and tapping the top
  3. from finch import Finch
  4. from random import randint
  5.  
  6. # Instantiate the Finch object and connect to Finch
  7. tweety = Finch()
  8.  
  9. left, right = tweety.obstacle()
  10.  
  11. # Do the following while no obstacles are detected by Finch
  12. while not left and not right:
  13.     # Get the accelerations
  14.     x, y, z, tap, shake = tweety.acceleration()
  15.  
  16.     # Print the acceleration data
  17.     print("X is %.2f gees, Y is %.2f gees, Z is %.2f gees, tap is %r shake is %r" % (x, y, z, tap, shake));
  18.  
  19.     # If a tap or shake has been detected recently, set the LED to a random color
  20.     if tap or shake:
  21.         tweety.led(randint(0,255), randint(0, 255), randint(0,255))
  22.  
  23.     # Get obstacles to use to exit loop
  24.     left, right = tweety.obstacle()
  25.    
  26. tweety.close()
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment