
To access the full video please subscribe to FLLCasts.com
- #1619
- 11 Jun 2020
Micro-Python 2.0: If motors are called from a variable, the program will stop running after calling them repeatedly in a loop. Make sure that the students have entered a variable to which the motor is given at the beginning of the program.
Examlpe solution to the task: "Program the robot to play the "DETECTED" sound file if the touch sensor is pressed.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) # Write your program here. ev3.speaker.beep() if touch.pressed(): ev3.speaker.play_file(SoundFile.DETECTED)
Example solution to the task : "Program the robot to play the "SNORING" sound file if the "if" condition is not met."
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) # Write your program here. ev3.speaker.beep() if touch.pressed(): ev3.speaker.play_file(SoundFile.DETECTED) else: ev3.speaker.play_file(SoundFile.SNORING)
Example solution to the task: "Make your program repeat forever."
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) # Write your program here. ev3.speaker.beep() while True: if touch.pressed(): ev3.speaker.play_file(SoundFile.DETECTED) else: ev3.speaker.play_file(SoundFile.SNORING)
Example solution to the task "Change your program so that when the touch sensor is pressed, the robot closes its clamp, otherwise it opens. Use the "run" command.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while True: if touch.pressed(): grabber.run(100) else: grabber.run(-100)
Example solution to the task "In a new program, instruct your robot to wait until the touch sensor is pressed and only then close its clip. Use the "run_angle" command.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while not touch.pressed(): pass grabber.run_angle(100, 60)
Example solution to the task "Program your robot, after waiting for its touch sensor to be pressed, to wait for it to be released before closing its clip." :
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while not touch.pressed(): pass while touch.pressed(): pass grabber.run_angle(100, 60)
Example solution to the task "Program your robot, after waiting for the touch sensor to released, to wait 200 milliseconds, and check to see if the touch sensor has been pressed again. Only if it is pressed again, let it close its clip.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while not touch.pressed(): pass while touch.pressed(): pass wait(200) if touch.pressed(): grabber.run_angle(100, 60)
Example solution to the task "Program the robot so that if the touch sensor has NOT been pressed again after waiting 200 milliseconds, to open its clip. Use the "else" operator.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while not touch.pressed(): pass while touch.pressed(): pass wait(200) if touch.pressed(): grabber.run_angle(100, 60) else: grabber.run_angle(-100, 60)
Example solution to the task "Make your whole program repeat forever.":
# Create your objects here. ev3 = EV3Brick() touch = TouchSensor(Port.S1) grabber = Motor(Port.A) # Write your program here. ev3.speaker.beep() while True: while not touch.pressed(): pass while touch.pressed(): pass wait(200) if touch.pressed(): grabber.run_angle(100, 60) else: grabber.run_angle(-100, 60)
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Python with LEGO Mindstorms EV3 - Level 2
In the second level of Python for EV3 robots, students learn in-depth the touch sensor. The sensor is used as an input device for manual control of machines, as well as a sensor for autonomous robots. In a pair of lessons, students build a control panel for the grabber and the movement of a crane. Programming wise, students learn how to fork code with "if-else" constructions, how to create conditional and forever loops with "while" and how to negate conditions with "not" operator. In the end of the lesson, robots can detect obstacles and avoid them, so that they traverse a simple labyrinth.
- 39
- 19:58
- 93

Lesson 2 - Grabber control panel
Introduction
Today we will create a robot that you can control with just tha press of a button. It will detect when you have pressed the button once and when you've pushed it twice. Based on this, it will either open or close its pincers and the objects within.
In this lesson, as well as the next one, we will be building a control console: first for the pincers, later for a crane. We will be looking at the sensors as a means of human interaction with the robots before we make autonomous robots with them.
What aspect of your daily life would you automate?
- 6
- 6
- 7
- 3d_rotation 2