#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
# This program requires LEGO EV3 MicroPython v2.0 or higher.
# Click "Open user guide" on the EV3 extension tab for more information.
# Create your objects here.
ev3 = EV3Brick()
left_motor = Motor(Port.C)
right_motor = Motor(Port.B)
color = DriveBase(left_motor, right_motor, wheel_diameter=57.15, axle_track=88.9)
while True:
if Button.DOWN in ev3.buttons.pressed():
ev3.light.on(Color.RED)
if Button.LEFT in ev3.buttons.pressed():
ev3.light.on(Color.YELLOW)
if Button.UP in ev3.buttons.pressed():
ev3.light.on(Color.GREEN)
if Button.RIGHT in ev3.buttons.pressed():
ev3.light.on(Color.ORANGE)
if Button.CENTER in ev3.buttons.pressed():
break
# Allows the user to switch through four colors. Hitting center exits the loop.
# Contrary to the name no I haven't figured out how to nest it or properly exit the loop without ending the program.
# Previously, after the loop, there was a beep and wait block to try preventing a total program exit, but this didn't change anything and still completely ended the loop. I tried adding another loop, but I didn't have time to put anything in the loop to test whether or not it works.