def main(): mac_address = "aa:bb:cc:dd:ee:ff" with Sphero(mac_address=mac_address) as sphero: sphero.power.wake() for i in range(20): sphero.user_io.set_all_leds_8_bit_mask(back_color=Color(blue=0xff)) sleep(0.25) sphero.user_io.set_all_leds_8_bit_mask(front_color=Color(red=0xff)) sleep(0.25) sphero.power.enter_soft_sleep()
def main(): mac_address = "d6:bc:6a:05:79:b6" with Sphero(mac_address=mac_address) as sphero: sphero.power.wake() for i in range(20): print('blink') sphero.user_io.set_all_leds_8_bit_mask(back_color=Color(blue=0xff)) sleep(0.25) sphero.user_io.set_all_leds_8_bit_mask(front_color=Color(red=0xff)) sleep(0.25) sphero.power.enter_soft_sleep() print('Exit with')
def main(): #mac_address = "aa:bb:cc:dd:ee:ff" mac_address = "f7:e2:c2:7d:4c:bb" with Sphero(mac_address=mac_address) as sphero: sphero.power.wake() sleep(2) sphero.user_io.set_all_leds_8_bit_mask() #testing = True #while(testing): #sphero.user_io.set_all_leds_8_bit_mask(front_color=Color(blue=255,green=255,red=255),back_color=Color(blue=255,green=255,red=255)) sphero.user_io.set_led_matrix_one_color(color=Color(blue=255)) #sphero.sensor.set_notify(notify_callback, CoreTime, Accelerometer) #sphero.sensor.cancel_notify_sensors() #sphero.sensor.cancel_notify_sensors() # while(sphero.sensor.get_ambient_light_sensor_value() <= 75): # print("Light Sensor: {}",sphero.sensor.get_ambient_light_sensor_value(), end="\r") # sphero.user_io.set_all_leds_8_bit_mask() # sleep(1) # sphero.user_io.set_all_leds_8_bit_mask(front_color=Color(blue=55)) # sphero.user_io.set_led_matrix_text_scrolling(string=":)",color=Color(blue=255,red=0,green=0)) # sleep(2) # sphero.driving.drive_with_heading(1, 270, Direction.forward) # sleep(.1) # sphero.driving.drive_with_heading(1, 90, Direction.forward) # sleep(.1) # sphero.driving.drive_with_heading(1, 0, Direction.forward) # sleep(1) # sphero.user_io.set_led_matrix_one_color(color=Color(green=255)) # sphero.driving.drive_with_heading(252, 5, Direction.forward) # sleep(3.2) # sphero.user_io.set_led_matrix_one_color(color=Color(red=255)) # sphero.driving.drive_with_heading(1, 0, Direction.forward) # sleep(2) # sphero.driving.drive_with_heading(200, 180, Direction.forward) # sleep(2) # sphero.driving.drive_with_heading(200, 200, Direction.forward) # sleep(.5) # sphero.driving.drive_with_heading(200, 180, Direction.forward) # sleep(1.5) # sphero.driving.drive_with_heading(1, 180, Direction.forward) # sphero.driving.reset_yaw() # sphero.driving.drive_with_heading(75, 90, Direction.forward) #sphero.driving.tank_drive(right_speed=255,left_speed=255) #sphero.user_io.set_led_matrix_one_color(color=Color(blue=255)) #sphero.user_io.set_led_matrix_single_character(symbol="*",color=Color(blue=255,red=255,green=255)) #sphero.user_io.set_led_matrix_text_scrolling(string="Get pi",color=Color(blue=255,red=255,green=255)) #sleep(5) #sphero.driving.raw_motor(left_speed=200,left_direction=DirectionRawMotor.reverse,right_speed=200,right_direction=DirectionRawMotor.forward) #sphero.driving.raw_motor(left_direction=Direction.reverse,left_speed=100,right_direction=Direction.forward,right_speed=200) #sphero.driving.drive_with_heading(255, 0, Direction.forward) sleep(40) sphero.power.enter_soft_sleep()
def happy_look_right(): with Sphero(mac_address=mac_address) as sphero: sleep(2) print("Look right") pixels = [ # Left Eye Pixel(x=1, y=2), Pixel(x=0, y=2), # Right Eye Pixel(x=6, y=2), Pixel(x=5, y=2) ] colors = [ # Left Eye Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff), # Right Eye Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff) ] for (pixel, color) in zip(pixels, colors): sphero.user_io.set_led_matrix_pixel(pixel, color)
def dizzy_look_left(): with Sphero(mac_address=mac_address) as sphero: sleep(2) print("Look left") pixels = [ # Left Eye Pixel(x=1, y=3), Pixel(x=2, y=3), # Right Eye Pixel(x=6, y=1), Pixel(x=7, y=1) ] colors = [ # Left Eye Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff), # Right Eye Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff) ] for (pixel, color) in zip(pixels, colors): sphero.user_io.set_led_matrix_pixel(pixel, color)
def normal_eyes(): with Sphero(mac_address=mac_address) as sphero: sleep(2) print("Show eyes in matrix") pixels = [ # Left Eye Pixel(x=0, y=1), Pixel(x=0, y=2), Pixel(x=0, y=3), Pixel(x=1, y=1), Pixel(x=1, y=2), Pixel(x=1, y=3), Pixel(x=2, y=1), Pixel(x=2, y=2), Pixel(x=2, y=3), # Right Eye Pixel(x=5, y=1), Pixel(x=5, y=2), Pixel(x=5, y=3), Pixel(x=6, y=1), Pixel(x=6, y=2), Pixel(x=6, y=3), Pixel(x=7, y=1), Pixel(x=7, y=2), Pixel(x=7, y=3) ] colors = [ # Left Eye Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), # Right Eye Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff), Color(red=0xff, green=0xff, blue=0xff) ] for (pixel, color) in zip(pixels, colors): sphero.user_io.set_led_matrix_pixel(pixel, color)
def main(): print("Connecting to Sphero...", end=" ") ### Connect to Sphero Bolt ### mac_address = "f7:e2:c2:7d:4c:bb" with Sphero(mac_address=mac_address) as sphero: print("DONE!") sphero.power.wake() sleep(2) sphero.user_io.set_all_leds_8_bit_mask() sleep(1) print("Gathering Pin Points...") getPinLocation(25) print("") print("DONE!") print("Gathering Sphero Points...") sphero.user_io.set_led_matrix_one_color(color=Color(blue=255)) getSpheroLocation(25) print("") print("DONE!") print("pinCoords:", pinCoords) print("roboCoords:", roboCoords) ### Calibration Run ### angle = 0 start = [roboCoords[0][0], roboCoords[0][1]] sleep(1) sphero.driving.drive_with_heading(0, 0, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, 0, Direction.forward) sleep(1) sphero.driving.drive_with_heading(0, 0, Direction.forward) sleep(1.25) oldCoords = roboCoords print("Gathering Sphero Points...") getSpheroLocation(25) print("") print("DONE!") print("roboCoords:", roboCoords) target = [roboCoords[0][0], roboCoords[0][1]] print("Calculating Angle...", end=" ") offset_angle = findangle(start, target) print("offset_angle:", offset_angle, "degrees") ### First Pin ### start = [roboCoords[0][0], roboCoords[0][1]] target = [pinCoords[0][0], pinCoords[0][1]] print("Calculating Angle...", end=" ") angle = findangle(start, target) angle = angle - offset_angle if angle < 0: print("its neg") angle = angle + 360 sleep(1) print("angle:", angle, "degrees") print("sending command to robot...") sleep(.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, angle, Direction.forward) sleep(2.5) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.25) ### Back up angle = 180 angle = angle - offset_angle if angle < 0: print("its neg") angle = angle + 360 print("sending command to robot...") sleep(.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, angle, Direction.forward) sleep(1) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) ### Second Pin ### print("Gathering Sphero Points...") getSpheroLocation(25) print("") print("DONE!") print("roboCoords:", roboCoords) print("Calculating Angle...", end=" ") start = [roboCoords[0][0], roboCoords[0][1]] target = [pinCoords[1][0], pinCoords[1][1]] angle = findangle(start, target) angle = angle - offset_angle if angle < 0: print("its neg") angle = angle + 360 print("angle:", angle, "degrees") print("sending command to robot...") sleep(.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, angle, Direction.forward) sleep(1.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.25) ### Back up angle = 180 angle = angle - offset_angle if angle < 0: print("its neg") angle = angle + 360 print("sending command to robot...") sleep(.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, angle, Direction.forward) sleep(1) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) ### Third Pin ### print("Gathering Sphero Points...") getSpheroLocation(25) print("") print("DONE!") print("roboCoords:", roboCoords) print("Calculating Angle...", end=" ") start = [roboCoords[0][0], roboCoords[0][1]] target = [pinCoords[2][0], pinCoords[2][1]] angle = findangle(start, target) angle = angle - offset_angle if angle < 0: print("its neg") angle = angle + 360 print("angle:", angle, "degrees") print("sending command to robot...") sleep(.25) sphero.driving.drive_with_heading(0, angle, Direction.forward) sleep(.75) sphero.driving.drive_with_heading(100, angle, Direction.forward) sleep(1.5) sphero.driving.drive_with_heading(0, angle, Direction.forward) sphero.power.enter_soft_sleep()