top of page
PYTHON

PYTHON
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
# Create your objects here
# Initialize the EV3 Brick.
ev3 = EV3Brick()
# Initialize a motor at port B.
test_motor = Motor(Port.B)
# Write your program here
# Play a sound.
ev3.speaker.beep()
# Run the motor up to 500 degrees per second. To a target angle of 90 degrees. test_motor.run_target(500, 90)
# Play another beep sound.
ev3.speaker.beep(frequency=1000, duration=500)
ONE MOTOR
This program makes your robot beep, rotate the motor, and beep again with a higher pitched tone. Run the program to make sure that it works as expected.
PYTHON
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
# Create your objects here
# Initialize the EV3 Brick.
ev3 = EV3Brick()
# Initialize the motors.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
# Initialize the drive base.
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)
# Go forward and backwards for one meter.
robot.straight(1000)
ev3.speaker.beep()
robot.straight(-1000)
ev3.speaker.beep()
# Turn clockwise by 360 degrees and back again. robot.turn(360)
ev3.speaker.beep()
robot.turn(-360)
ev3.speaker.beep()
2 MOTORS
This example project shows how you can make a robotic vehicle drive for a given distance or turn by a given angle.

bottom of page