Last active
August 29, 2015 14:19
-
-
Save hyperobject/88d198ee46102f809e41 to your computer and use it in GitHub Desktop.
Controlling the cloudBit with the Leap Motion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leap # I assume you've already figured out how to use the Leap Motion SDK for this | |
import partlycloudy as cloud | |
bit = cloud.Bit('authentication token', 'bit ID') # get these from littleBits cloud control | |
controller = Leap.Controller() # init Leap Motion | |
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE) # make sure that the controller will recognize swipes | |
while True: | |
frame = controller.frame() # grab a leap motion frame | |
for gesture in frame.gestures(): | |
if gesture.type is Leap.Gesture.TYPE_SWIPE: | |
g = Leap.SwipeGesture(gesture) # create the gesture object | |
if g.direction.x > 0: # to the right - we'll use this for 'on' | |
bit.output(100,-1) # full power | |
else: | |
bit.output(0,-1) # turn off | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leap # I assume you've already figured out how to use the Leap Motion SDK for this | |
import partlycloudy as cloud | |
bit = cloud.Bit('authentication token', 'bit ID') # get these from littleBits cloud control | |
controller = Leap.Controller() # init Leap Motion | |
while True: | |
frame = controller.frame() # grab a leap motion frame | |
height = frame.hands[0].stabilized_palm_position.y / 4 # y position goes from 0 to ~400, so we divide by 4 to fit in the cloudBit's range | |
bit.output(height, -1) # set output to height | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment