async def on_start(vm, stack): ms_hub.status_light.on("black") rotate_hub_display_to_value("3") blinking_frames = [hub.Image(frame) for frame in blinking_animation] vm.system.display.show(blinking_frames, clear=False, delay=round(1000 / 8), loop=True, fade=1) left_hand = Motor("B") right_hand = Motor("F") # Calibrate left_hand.run_to_position(0) right_hand.run_to_position(0) vm.system.sound.play("/extra_files/Humming") for i in range(2): right_hand.run_for_degrees(-100, 50) right_hand.run_for_degrees(100, 50) left_hand.run_for_degrees(100, 50) left_hand.run_for_degrees(-100, 50) left_turn = MotorPair("B", "E") right_turn = MotorPair("A", "F") vm.system.sound.play("/extra_files/Humming") for i in range(2): right_turn.move(100, "degrees", steering=100, speed=50) right_turn.move(-100, "degrees", steering=100, speed=50) left_turn.move(100, "degrees", steering=-100, speed=50) left_turn.move(-100, "degrees", steering=-100, speed=50) wheels = MotorPair("A", "E") wheels.move(14 * math.pi, "cm", steering=100, speed=80) wheels.move(14 * math.pi, "cm", steering=-100, speed=80) right_hand.run_to_position(270, direction="counterclockwise") wait_for_seconds(1) right_hand.run_for_seconds(1, 50) await vm.system.sound.play_async("/extra_files/Tadaa") wait_for_seconds(1) right_hand.run_to_position(0, direction="counterclockwise")
motors_wheels.move(3, unit='cm') print("DONE!") # %% # Fire first drum blaster print("Firing first drum blaster...") motors_wheels.move(2.5, unit='cm', steering=-100) for ii in range(0, 3): motor_right_arm.start_at_power(40) wait_for_seconds(0.12) motor_right_arm.start_at_power(-40) wait_for_seconds(0.12) motor_right_arm.run_to_position(300, direction='shortest path') motor_left_arm.run_for_seconds(0.5, speed=-100) motor_left_arm.run_to_position(25, direction='shortest path') print("DONE!") # %% # Fire second drum blaster print("Firing second drum blaster...") motors_wheels.move(5, unit='cm', steering=100) for ii in range(0, 4): motor_left_arm.start_at_power(-40) wait_for_seconds(0.12) motor_left_arm.start_at_power(40) wait_for_seconds(0.12) motor_left_arm.run_to_position(60, direction='shortest path')
print("DONE!") # %% [markdown] # # Make Charlie respond to color # If red was detected, we get out of the while loop and execute the following code. # In other words, this is Charlie's response to the color. # %% # Stop movement. motors_wheels.stop() # %% hub.light_matrix.show_image('HAPPY') app.play_sound('Doorbell 1') # %% # Open and close Charlie's hatch. motor_right_arm.run_for_seconds(1) wait_for_seconds(3) app.play_sound('Tada') motor_right_arm.run_to_position(0, direction='counterclockwise') wait_for_seconds(3) # %% # Turn off everything. distance_sensor.light_up_all(0) color_sensor.light_up_all(0) # %% print("-" * 15 + " Execution ended " + "-" * 15 + "\n")
# %% hub.status_light.on('black') # %% [markdown] # # Configure motors # %% print("Configuring motors...") motor_wheel = Motor('E') # Wheel (for turning around) motor_left_arm = Motor('B') # Left arm motor_left_arm.set_default_speed(-80) print("DONE!") # %% print("Setting arm motor to initial position...") motor_left_arm.run_for_seconds(1) print("DONE!") # %% [markdown] # # Configure sensor # %% print("Configuring color sensor...") color_sensor = ColorSensor('C') print("DONE!") # %% [markdown] # # Hit ball # %% while (True):
motors_af.move(-100, unit='degrees', steering=-100) motors_af.move(100, unit='degrees', steering=-100) motors_be.move(100, unit='degrees', steering=-100) motors_be.move(-100, unit='degrees', steering=-100) print("DONE!") # %% print("Dancing steps 3...") motors_motion = MotorPair('A', 'E') motors_motion.move(40, unit='cm', steering=100) motors_motion.move(40, unit='cm', steering=-100) # Open hatch motor_f.run_to_position(270, direction='counterclockwise') wait_for_seconds(1) motor_f.run_for_seconds(1) app.play_sound('Tada') motor_f.run_to_position(0, direction='counterclockwise') print("DONE!") # %% print("-" * 15 + " Execution ended " + "-" * 15 + "\n")