wait_for_seconds(0.01)

        print(str(timer_drums.now()))

    return None


# %% [markdown]
# ## Repeat the part of `drum_solo`

# %%
print("Executing drum_solo part...")

# %%
app.start_sound('Triumph')
hub.light_matrix.show_image('MUSIC_QUAVER')

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

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)
        color_idx = counter % n_colors
        print("Right button changed color to " + colors[color_idx] +
              "(color_idx = " + str(color_idx) + "; counter = " +
              str(counter) + ")")

    if hub.left_button.was_pressed():
        # If the left button was pressed, save the current color as the player's guess.
        guessed_color = colors[color_idx]
        print("Guessed color is " + guessed_color)

        # Check if the player's guess was correct.
        if guessed_color == chosen_color:

            # If the user guessed the color, provide positive feedback.
            # (S)he won!
            app.start_sound('Tada')
            hub.light_matrix.show_image('YES')
            correct_guess = True  # This makes sure we won't go through the loop again.

            print("That is correct :) ! The chosen color was " +
                  guessed_color + ". You win!")

        else:
            # If the user didn't guess the color, provide negative feedback.
            app.start_sound('Lose')
            hub.light_matrix.show_image('NO')
            wait_for_seconds(4)
            hub.light_matrix.off()

            # To make things easier for the player, we will remove the wrong
            # color of the list, so it isn't displayed again.
예제 #3
0
# %%
print("Setting arm motors to position 0...")
motor_b = Motor('B')  # Left arm
motor_f = Motor('F')  # Right arm
motor_b.run_to_position(0)
motor_f.run_to_position(0)
print("DONE!")

# %% [markdown]
# # Dance time!

# %%
print("Dancing steps 1...")

app.start_sound('Party Blower')

for ii in range(0, 2):
    motor_f.run_for_degrees(-100)
    motor_f.run_for_degrees(100)

    motor_b.run_for_degrees(100)
    motor_b.run_for_degrees(-100)

print("DONE!")

# %%
print("Dancing steps 2...")

app.start_sound('Party Blower')
예제 #4
0
        wait_for_seconds(0.01)  # Small pause between steps.

        # We also print the time in console.
        print(str(timer_drums.now()))

    return None


# %% [markdown]
# Now we can actually drum away!

# %%
print("Starting drumming...")

app.start_sound('Triumph')
hub.light_matrix.show_image('MUSIC_QUAVER')

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

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

print("DONE!")

# %%
print("Going for the finale...")

motor_left_arm.run_to_position(15)
motor_right_arm.run_to_position(345)
예제 #5
0
        # Charlie will get embarrassed if you get closer than 30 cm
        # For now, I defined this distance as 15 cm for testing purposes.
        distance_threshold = 15
        if distance < distance_threshold:

            print("Charlie is embarrassed! (distance = " + str(distance) + " cm)")

            # Turn off the lights of the distance sensor.
            print("Turning off the distance sensor...")
            distance_sensor.light_up_all(0)
            print("DONE!")

            # Charlie runs away out of shyness.
            print("Charlie is running away!")        
            hub.light_matrix.show_image('CONFUSED')
            app.start_sound('Cuckoo')

            
            motors_arms.move(-90, unit='degrees')

            motors_wheels.move(-15, unit='cm')
            motors_wheels.move(20, unit='cm', steering=100)

            app.start_sound('Cuckoo')

            motors_wheels.move(30, unit='cm')
            motors_wheels.move(20, unit='cm', steering=100)

            app.start_sound('Cuckoo')

            motors_arms.move(90, unit='degrees')