Program Review: Random Distance
- The program shown below is sample code for making your robot move for a random distance.
Random Block
Numeric
Generates a random number between 1 and 100.
Sends the number out through the wire on its 'Value' terminal () plug.
Sends a randomly generated number to the Move Block's 'Rotations' terminal () plug.
Move Steering Block
On for Rotations
Moves the robot forward at 50% power for the number of rotations wired into the 'Rotations' terminal () plug.
Moves forward for a random number of rotations.
Program Review: Dangerous Wall
- The program shown below is sample code for the mini-challenge.
Program Review: Multiple Lines Display
- The program shown below is sample code displaying text on multiple lines.
Display Block
Text - Pixels
Clears the screen, then writes the text "Rotation B: " at coordinate (10, 20)
of the EV3 screen.
Writes "Rotation B: " in the top left corner of the EV3 screen.
Motor Rotation Sensor Block
Measure - Rotations
Reads the Motor (B) Rotation Sensor's number of rotations.
Sends the sensor reading out through the wire on its 'Rotations' terminal () plug.
Sends the number of rotation from Motor B from the sensor to
Display Block's 'Text' terminal() plug.
Display Block
Text - Pixels
Without clearing the screen, writes the value wired into the 'Text' terminal
()
plug at coordinate (100, 20) of the EV3 screen.
Writes the number of Motor B wheel rotation next to "Rotation B: " on the screen.
Display Block
Text - Pixels
Without clearing the screen, then writes the text "Rotation C: " at coordinate (10, 50)
of the EV3 screen.
Writes "Rotation C: ", below "Rotation B: ", on the EV3 screen.
Motor Rotation Sensor Block
Measure - Rotations
Reads the Motor (C) Rotation Sensor's number of rotations.
Sends the sensor reading out through the wire on its 'Rotations' terminal () plug.
Sends the number of rotation from Motor C from the sensor to
Display Block's 'Text' terminal() plug.
Display Block
Text - Pixels
Without clearing the screen, writes the value wired into the 'Text' terminal
()
plug at coordinate (100, 50) of the EV3 screen.
Writes the number of Motor C wheel rotation next to "Rotation C: " on the screen.
Display Block
Text - Pixels
Without clearing the screen, then writes the text "Ultrasonic : cm" at coordinate (10, 80)
of the EV3 screen.
Writes "Ultrasonic : cm" onto the bottom left corner of the EV3 screen.
Ultrasonic Sensor Block
Measure - Distance Centimeters
Reads the Ultrasonic Sensor in centimeters.
Sends the sensor reading out through the wire on its 'Distance in Centimeters' terminal () plug.
Sends the centimeter value read from the sensor to
Display Block's 'Text' () plug.
Display Block
Text - Pixels
Without clearing the screen, writes the value wired into the 'Text'
terminal ()
plug at coordinate (110, 80) of the EV3 screen.
Writes the value of Ultrasonic Sensor between "Ultrasonic : " and "cm"
on the screen.
Wait Block
Time Indicator
Stops the program from processing additional commands
until 5 seconds have passed.
Robot displays the information written on its screen for 5 seconds.
Program Review: Display Rotation in Centimeters
- The program shown below is sample code for making your robot display the wheel rotation in centimeters.
Wait Block
Time Indicator
Stops the program from processing additional commands
until 3 seconds have passed.
Robot does nothing for 3 seconds so that user can manipulate
the wheel rotation manually to create Motor Rotation Sensor inputs.
Display Block
Text - Pixels
Clears the screen, then writes the text "Rotation B: " at coordinate (10, 20)
of the EV3 screen.
Writes "Rotation B: " onto the top left corner of the EV3 screen.
Motor Rotation Sensor Block
Measure - Rotations
Reads the Motor (B) Rotation Sensor's number of rotation.
Sends the sensor reading out through the wire on its 'Rotations' terminal () plug.
Sends the number of rotation from Motor B from the sensor to
Math Block's 'a' terminal () plug.
Math Block
Multiply
Performs calculation, 'a' times 'b', where 'a' is wired in,
and 'b' is set to 17. Sends the result out through the wire on its '=' terminal plug.
Takes number of rotation from Motor B and multiplies it by 17.
Sends the result to Display Block's 'Text' terminal () plug.
Display Block
Text - Pixels
Without clearing the screen, writes the value wired into the 'Text' terminal () plug at coordinate (100, 20) of the EV3 screen.
Writes the number of Motor B rotation converted to centimeters
next to "Rotation B: " on the screen.
Display Block
Text - Pixels
Without clearing the screen, writes the text "Rotation C: " at coordinate (10, 50)
of the EV3 screen.
Writes "Rotation C: ", below "Rotation B: " on the EV3 screen.
Motor Rotation Sensor Block
Measure - Rotations
Reads the Motor (C) Rotation Sensor's number of rotation.
Sends the sensor reading out through the wire on its 'Rotations' terminal () plug.
Sends the number of rotation from Motor C from the sensor to
Math Block's 'a' terminal () plug.
Math Block
Multiply
Performs calculation, 'a' times 'b', where 'a' is wired in,
and 'b' is set to 17. Sends the result out through the wire on its '=' terminal plug.
Takes number of rotation from Motor C and multiplies it by 17.
Sends the result to Display Block's 'Text' terminal () plug.
Display Block
Text - Pixels
Without clearing the screen, writes the value wired into the 'Text' terminal
()
plug at coordinate (100, 50) of the EV3 screen.
Writes the number of Motor C rotation converted to centimeters
next to "Rotation C: " on the screen.
Wait Block
Time Indicator
Stops the program from processing additional commands
until 5 seconds have passed.
Robot displays the information written on its screen for 5 seconds.
Program Review: Move for Centimeters My Block
- The program shown below is sample code for using a My Block
that takes an input number as centimeters,
convert it into a number of
rotations, and use it to drive the robot forward.
My Block Connector Block
for My Block 'MoveForCM'
Outputs the value wired into My Block named 'MoveForCM'
placed in 'MoveForCM_main.evp3'.
Sends the user specified constant value
to Math Block's 'a' terminal () plug.
Math Block
Divide
Performs calculation, 'a' divided by 'b', where 'a' is wired in,
and 'b' is set to 17. Sends the result out through the wire on its '=' terminal.
Takes the number of desired Centimeters (from the Constant Block)
and converts it into number of wheel rotations by dividing it by 17.
Sends the result to Move Block's 'Rotation terminal
() plug.
Move Steering Block
On for Rotations
Moves the robot forward at 50% power for the number of rotations
wired in into the 'Rotations' terminal () plug.
Moves forward for a number of rotations calculated from user specified centimeters.
Program Review: Obstacle Detection Until Black Line
- The program shown below is sample code for mini-challenge in the "Obstacle Detection" lesson.