play_drums(bars=4, tempo=80)
play_drums(bars=4, tempo=130)

# %%
motor_left_arm.run_to_position(15)
motor_right_arm.run_to_position(345)

for ii in range(0, 8):

    wait_for_seconds(0.1)
    motors_arms.start_at_power(50, steering=-100)
    wait_for_seconds(0.1)
    motors_arms.start_at_power(-50, steering=-100)

app.play_sound('Tada')
motor_left_arm.run_to_position(0, direction='shortest path')
motor_right_arm.run_to_position(0, direction='shortest path')

# %%
print("DONE!")

# %% [markdown]
# ## Actual `drum_master` part

# %%
motor_left_arm.run_to_position(60)
motor_right_arm.run_to_position(335)

# Hit that pedal, baby
print("Hitting the pedal...")
# * `Toliet Flush`
# * `Toy Honk`
# * `Toy Zing`
# * `Traffic`
# * `Train Breaks`
# * `Train Horn 1` or `Train Horn 2` or `Train Horn 3`
# * `Train On Tracks`
# * `Train Signal 1` or `Train Signal 2`
# * `Train Start`
# * `Train Whistle`
# * `Triumph`
# * `Tropical Birds`
# * `Wand`
# * `Water Drop`
# * `Toliet Flush` (TODO: check spelling)
# * `Whiz 1` or `Whiz 2`
# * `Window Breaks`
# * `Win`
# * `Wobble`
# * `Wood Tap`
# * `Zip`

# %%
sound = 'Tada'
volume = 75

# %%
print("Playing sound '" + sound + "' with volume " + str(volume) + "...")
app.play_sound(sound, volume)
print("DONE!")
Пример #3
0
            print("Invalid randon number. Doing nothing.")

        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("Skiing...")

# Original value is 6.
# I set this to 3 due to space constraints.
n_pushes = 3

for ii in range(0, n_pushes):

    # Now, we move the arm motors back to position 0 sequentially.
    # This doesn't affect the movement, but looks a bit clumsy.
    # An alternative to this could be using coroutines to
    # make them run "parallel", as in the drum_solo project.
    motor_left_arm.run_to_position(0, direction='shortest path')
    motor_right_arm.run_to_position(0, direction='shortest path')
    motors_arms.move(85, unit='degrees')

    motor_right_arm.start()
    t_wait = 0.1
    wait_for_seconds(t_wait)
    motor_right_arm.stop()

motor_left_arm.run_to_position(0, direction='shortest path')
motor_right_arm.run_to_position(0, direction='shortest path')

app.play_sound('Skid')

print("DONE!")

# %%
print("-" * 15 + " Execution ended " + "-" * 15 + "\n")
Пример #5
0
    print("TAPPED!")

    print("Displaying surprised face...")
    hub.light_matrix.show_image('SURPRISED')
    print("DONE!")

    wait_for_seconds(1)

    print("Raise hands...")
    motor_pair = MotorPair('B', 'F')
    motor_pair.set_default_speed(50)
    motor_pair.move(-90, unit='degrees')  # Negative angle raises the hands.
    print("DONE!")

    print("Saying 'Hi!'...")
    app.play_sound('Robot 2', 75)
    print("DONE!")

    wait_for_seconds(1)

    print("Lower hands...")
    motor_pair.move(90, unit='degrees')  # Positive angle lowers the hands.
    print("DONE!")

    wait_for_seconds(1)

    print("Displaying happy face...")
    hub.light_matrix.show_image('HAPPY')
    print("DONE!")

# %%
Пример #6
0
timer = Timer()


def high_five_or_no_high_five():
    # Original threshold of speed is -10.
    # However, in my experience, -5 worked better.
    return (motor_right_arm.get_speed() < -5) or (timer.now() > 5)


# Wait for either a high five or for the timer to go past 5 s.
wait_until(high_five_or_no_high_five)

# If the timer exceeded 5, it means that there was no high five.
if timer.now() > 5:
    print("No high five :( ")
    hub.light_matrix.show_image('SAD')
    app.play_sound('Lose')
    motor_right_arm.run_to_position(0, direction='shortest path')
    motors_wheels.move(-20, unit='cm')

# Otherwise, it means that there was a high five.
else:
    print("High five :) ")
    hub.light_matrix.show_image('HAPPY')
    app.play_sound('Crazy Laugh')
    motor_right_arm.run_to_position(0, direction='shortest path')

# %%
print("-" * 15 + " Execution ended " + "-" * 15 + "\n")