The distance sensor is located in the front of the robot, and it can measure the the distance between the robot and an object.
Understanding the while loop -
"while 1 = 1" will always be true.
using the while block like this is the same as using a forever block.
in most scrip languages there is no forever command, so coders will use a line of code like this,
while ( 1 = 1)
or command might just be "while true" like this
while (true)
LEARNING ACTIVITY
In this program the the first while block should make the code run forever.
the second while block or the indented block
should only happen when there is something
in front of the distance sensor.
Try this code and see how it works.
Move a target block around in front of the robot.
NOTE the arm in the down position sometimes will be "seen" by the sensor so if you get strange "readings" you can lift the arm out of the way.
(hint - Lesson 5 - using the arm)
The distance sensor can also use math operators like this to compare numbers. Make this code and test it.
Putting it all together!
Set a few of the target blocks a few feet in front of the robot.
Using the sensor make the robot drive forward towards the target blocks and stop a few inches before it hits the blocks.
Bonus add in the TouchLED as an indictor light as it drives.
Bonus2 add in sound indicators.
Show the completed program to your instructor.
Save the finished program. (lesson12.iqblocks)
Then Save_As to make a copy (lesson14.iqblocks)
Make sure the files are in the shared google drive folder.
If you are using the web version of the app, click on the name of the file in the top center of the screen, then use File and Save To Your Device
fun fact! 13 is considered unlucky - In some tall buildings and most cruise ships there no floor 13 or deck 13 Most elevators in tall buildings and on cruise ships do not have a button for floor 13. Because of this old superstition. That is why we are skipping lesson 13 in this project.