Ejemplo n.º 1
0
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import InfraredSensor
from pybricks.parameters import Port, Button
from pybricks.tools import wait
from pybricks.media.ev3dev import SoundFile, Font

# Create the brick connection.
ev3 = EV3Brick()

# Set Font.
print_font = Font(size=16, bold=True)
ev3.screen.set_font(print_font)

# Initialize IR sensor.
ir = InfraredSensor(Port.S4)

# Adjust voice.
ev3.speaker.set_speech_options('en', 'f3', 25, 50)
ev3.speaker.set_volume(50)

# Check a pressed button and name it.
while True:
    buttons = ir.buttons(1)
    wait(10)
    if Button.BEACON in buttons:
        ev3.speaker.say('beacon')
        break
    
    elif Button.LEFT_UP in buttons and Button.RIGHT_UP in buttons:
        ev3.speaker.play_file(Sound.UP)