Example solution to the task "Program the robot to dynamically check the right touch sensor (with an "if" statement in a loop) and to drive the right motor infinitely when pressed.":
# Create your objects here.
ev3 = EV3Brick()
right_touch = TouchSensor(Port.S2)
right_motor = Motor(Port.C)
# Write your program here.
ev3.speaker.beep()
while True:
if right_touch.pressed():
right_motor.run(1000)
Example solution to the task "Program the robot to drive the right motor indefinitely in the opposite direction if the right touch sensor is NOT pressed.":
# Create your objects here.
ev3 = EV3Brick()
right_touch = TouchSensor(Port.S2)
right_motor = Motor(Port.C)
# Write your program here.
ev3.speaker.beep()
while True:
if right_touch.pressed():
right_motor.run(1000)
else:
right_motor.run(-1000)
Example solution to the task "Change your program so that the robot checks the left touch sensor and to drive the left motor.":
# Create your objects here.
ev3 = EV3Brick()
left_touch = TouchSensor(Port.S1)
left_motor = Motor(Port.B)
# Write your program here.
ev3.speaker.beep()
while True:
if left_touch.pressed():
left_motor.run(1000)
else:
left_motor.run(-1000)
Example solution to the task "Program your robot to dynamically check both sensors and drive their respective motors.":
# Create your objects here.
ev3 = EV3Brick()
right_touch = TouchSensor(Port.S2)
left_touch = TouchSensor(Port.S1)
right_motor = Motor(Port.C)
left_motor = Motor(Port.B)
# Write your program here.
ev3.speaker.beep()
while True:
if right_touch.pressed():
right_motor.run(1000)
else:
right_motor.run(-1000)
if left_touch.pressed():
left_motor.run(1000)
else:
left_motor.run(-1000)
Example solution to the task "Change your program so that instead of the robot moving back, it stops its motors when their respective touch sensors are not pressed.":
# Create your objects here.
ev3 = EV3Brick()
right_touch = TouchSensor(Port.S2)
left_touch = TouchSensor(Port.S1)
right_motor = Motor(Port.C)
left_motor = Motor(Port.B)
# Write your program here.
ev3.speaker.beep()
while True:
if right_touch.pressed():
right_motor.run(1000)
else:
right_motor.brake()
if left_touch.pressed():
left_motor.run(1000)
else:
left_motor.brake()