from sphero import core import time s = core.Sphero("/dev/tty.Sphero-OOB-AMP-SPP") print "Connecting to Sphero..." s.connect() def doTheDance(): speed = 0x88 sleepTime = 1 s.roll(speed, 1) time.sleep(sleepTime) s.roll(speed, 90) time.sleep(sleepTime) s.roll(speed, 180) time.sleep(sleepTime) s.roll(speed, 270) time.sleep(sleepTime) squares = 3 while squares > 0: doTheDance() time.sleep(0.1) squares -= 1
# -*- coding: utf-8 -*- # Ten plik ustanawia polaczenie ze Sphero # oraz definuje zmienna sphero, ktora moze # byc uzywana do komunikacji from sphero import core import time nazwa_sphero = "/dev/tty.Sphero-WYW-AMP-SPP" # dla windowsa : "COM-3" # dla linuxa : sparowac MAC adres z linkiem w /dev/ # timeout na połączenie timeout_na_polaczenie = 10 # utwórz Sphero, które będzie używane w kodzie sphero = core.Sphero(nazwa_sphero) # nawiąż połączenie sphero.connect() # dodaj customową funkcję czekaj w Sphero sphero.czekaj = time.sleep print "[i] Sphero skonfigurowane poprawnie. Jeszcze chwilkę..." time.sleep(timeout_na_polaczenie) # wyłącz stabilizację # sphero.set_stabilization(True) # sphero.set_rotation_rate(0xFF) sphero.roll(1, 1) print "[i] Połączono ze Sphero."
from random import randint from sphero import core import time # this program is a simple implementation of a game, # where the user is supposed to guess the number # in a range 1 to 100, while the program can give # him a hint, whether the number provided is greater, # equal or less to the one provided by the player # pulse rate means how close is user to guess the number # the smaller the value is, the closer the user is. # range: 0-100 s = core.Sphero("/dev/tty.Sphero-OOB-AMP-SPP") #create Sphero controller print "Connecting to Sphero..." s.connect() #initialize connection def show_hint_in_sphero(pulse_rate): print "pulse rate: %s" % pulse_rate green_channel = abs(255 - int(pulse_rate * 2.55)) % 255 color = "10,%s,10" % (green_channel) s.set_rgb(0, green_channel, 0) print "color: " + color def show_hint(difference): if difference > 0: print "My number is greater!" else: