HTML

kaitlynbowmanex1.py

Nov 18th, 2016
192
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # A simple program that changes the Finch LED based on orientation.
  2.  
  3. from finch import Finch
  4. from random import randint
  5. tweety = Finch()
  6.  
  7. left, right = tweety.obstacle()
  8.  
  9. # Do the following while no obstacles are detected by Finch
  10. while not left and not right:
  11.     x, y, z, tap, shake = tweety.acceleration()
  12.     # Print the acceleration data
  13.     print("X is %.2f gees, Y is %.2f gees, Z is %.2f gees, tap is %r shake is %r" % (x, y, z, tap, shake));
  14.     # Use the acceleration data to set the LED:
  15.     # beak up
  16.     if x < -0.7 and y > -0.3 and y < 0.3 and z > -0.3 and z < 0.3:
  17.         tweety.led(255,0,0);
  18.     # beak down
  19.     elif x > 0.7 and y > -0.3 and y < 0.3 and z > -0.3 and z < 0.3:
  20.         tweety.led(0,255,0);
  21.     # level
  22.     elif x > -0.5 and x < 0.5 and y > -0.5 and y < 0.5 and z > 0.7:
  23.         tweety.led(0,0,255);
  24.     # upside down
  25.     elif x > -0.5 and x < 0.5 and y > -0.5 and y < 0.5 and z < -0.7:
  26.         tweety.led(0,255,255);
  27.     # left wheel down
  28.     elif x > -0.5 and x < 0.5 and y > 0.7 and z < 0.5 and z > -0.5:
  29.         tweety.led(255,255,0);
  30.     # right wheel down
  31.     elif x > -0.5 and x < 0.5 and y < -0.7 and z < 0.5 and z > -0.5:
  32.         tweety.led(255,0,255);
  33.  
  34.     # Get obstacles to use to exit loop
  35.     left, right = tweety.obstacle()
  36.    
  37. tweety.close()
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment