Base Mission
1 point Live judgedAll three Unstraight Cubes satisfy the definition (cubes are the black line).
Discovery · Coding Project 10
Student PIN:
Imagine the power is out and you are trying to cross a room you know well. Your eyes are useless. So you put a hand out in front of you and start walking.
Actually do it. Stand a few steps from a wall, close your eyes, put one hand out, and walk slowly toward it until you touch it.
You did not check once and hope. What were you doing the whole time you were walking?
That Is a Loop
Check. Step. Check. Step. Check — touched something — stop and do something different.
Repeating an action while you wait for something to become true is called looping, and it is the whole idea of this project.
Tip your kit’s sensors out on the table. Without looking anything up, sort them into two piles. You decide the rule.
| My rule for splitting them | What went in each pile |
|---|---|
| Pile 1 | |
| Pile 2 |
One Split Matters More Than the Others
Some of your sensors work like a light switch — pressed or not pressed, and nothing in between. Others give you a whole range of readings.
If that is how you sorted them, you found the split that programmers care about. If not, re-sort them that way now.
A sensor is like a light switch. Two readings, nothing between:
0: not touched1: touchedA touch sensor is a mechanical switch. Pressing it pushes two contacts together and completes a circuit.
An sensor gives a whole range of numbers, from 0 to 4095. Light sensors and rangefinders work this way — “how bright,” not “bright or dark.”
You will meet these later. Today, everything is 0 or 1.
0 and 1 Mean More Than Numbers
In programming, 1 means true, yes, on and 0 means false, no, off. That is why a sensor reading of 1 can be read as “yes, I am touching something.”
Every time you needed the robot to wait, you used msleep(). That will not work now.
The program cannot read a sensor while it is sleeping. If you tell it to sleep for two seconds and the sensor is pressed after half a second, the robot never notices.
You need it to keep checking — over and over, as fast as it can. That is what a loop is for.
To check something, you compare two values. These are the comparisons you can use:
| Symbol | Means | Example |
|---|---|---|
== | is equal to | 5 == 4 is false |
!= | is not equal to | 5 != 4 is true |
> | is greater than | 5 > 4 is true |
< | is less than | 5 < 4 is false |
>= | is greater than or equal to | 5 >= 5 is true |
<= | is less than or equal to | 5 <= 5 is true |
⚠ Two Equals Signs, Not One
One = means make this equal to that — it is what you used to set a in Project 9.
Two == means is this equal to that? — it is a question.
Use one where you meant two and your program may still and run, then do something wrong. This is one of the hardest bugs to find, so check it every time.
Say it in plain English before you say it in C:
while it is raining
{
my umbrella is open and over my head
}
close the umbrellaThe umbrella stays up the whole time the is true. The moment it stops raining, you fall out of the and close it.
| Code / part | What it means |
|---|---|
| while (condition) | Ask the question. No here — the braces do that job, same as int main (). |
{ ... } | Everything inside runs, over and over, as long as the answer is true. |
after the } | The moment the answer is false, the robot jumps down here. |
digital(0) reads the digital sensor plugged into 0. It gives you a 0 or a 1.
// While not touched
while (digital(0) == 0)
{
// Keep driving
motor(0, 100);
motor(3, 100);
// Tiny pause to avoid overworking the controller
msleep(10);
}
motor(0, 0);
motor(3, 0);
// Touched: Stop
msleep(30);Read It Out Loud
“While the sensor in port 0 reads zero — while nothing is it — keep both motors running. As soon as it reads one, stop.”
Notice the loop condition is checking for 0, not 1. You keep going while it is not pressed. Students often mix this up.
⚠ No msleep, No ao Inside the Loop
Do not put a long msleep() in the loop — it stops the checking. Do not put ao() in the loop either, or the robot will start and stop over and over instead of driving.
The ao() goes after the closing brace. That is the whole point: the loop is the driving, and what comes after is what happens when the condition finally changes.
Mount your touch sensor on the front of the robot so it hits things before anything else does. Plug it into a digital port and write down which one.
On the Wombat, open the sensor list. Press the sensor with your finger and watch the number.
| Question | My answer |
|---|---|
| Which digital port is my touch sensor in? | |
| What does it read when nothing touches it? | |
| What does it read when I press it? |
⚠ Hold the Robot in the Air for the First Run
Do not put this on a table or the field yet. Hold the robot up so the wheels spin freely, run the program, then press the sensor with your finger and watch the wheels stop.
A loop that never sees its sensor never stops. Find that out in your hands, not off the edge of a table.
Create a new project called Drive Until Bump. Plan it as first, then write it.
// 1. Print a message so I know it started
// 2. While the sensor is NOT pressed, drive forward
// 3. When it is pressed, fall out of the loop
// 4. Stop
You spent Project 9 learning why bare numbers are a bad idea. Do not abandon that now.
int left = 0;
int right = 3;
// Front touch sensor
int bump = 0;
while (digital(bump) == 0)
{
motor(left, 100);
motor(right, 100);
msleep(10);
}
motor(0, 0);
motor(3, 0);
msleep(30);Note that bump and left both hold 0 — but they mean completely different things. One is a digital port, one is a motor port. The names are what keep them straight.
Change == 0 to == 1. Before you run it, write down what you think will happen.
My prediction:
Now run it. Then run it again while holding the sensor pressed the whole time.
What actually happened, both times?
Explain why, using the words “true” and “false”.
Put it back to == 0.
Here is what makes a touch sensor genuinely useful: a wall is a place your robot can always find.
New project. Drive backward until the sensor presses against the starting box wall, then drive forward a set distance into the box and stop.
// 1. Drive backward while the sensor is not pressed
// 2. Exit the loop when it touches the wall
// 3. Stop and settle
// 4. Drive forward a set distance
// 5. Stop
Why This Matters More Than It Looks
No matter where the robot wandered off to, it can come back and touch a wall — and now it knows exactly where it is. Every measurement after that starts from a spot it can trust.
A robot that has been driving is still moving when the loop ends. Momentum does not care about your program.
Put a proper stop between the loop and whatever comes next:
motor(0, 0);
motor(3, 0);
msleep(30);
// Let the robot actually stop moving
msleep(500);Run it with and without the pause and compare.
What difference did the pause make?
The Wombat has one physical push button and three soft buttons on screen, named a, b, and c. Each has a that returns 1 when pressed and 0 when not.
printf("Press A to start\n");
while (a_button() == 0)
{
// Wait: do nothing at all
msleep(10);
}
// Run the mission
Add this to the top of a program. Now your robot waits for you instead of driving off the second it compiles.
This loop has nothing inside it but a tiny pause. Is it still doing something? What?
Mission 13 All three Unstraight Cubes satisfy the definition (cubes are the black line). Two Unstraight Cubes form a scoring stack — one Unstraight Cube is another. All three Unstraight Cubes form a scoring stack. All cubes must originate from the Unstraight Cube area.Rebuild the Shipment
Watch Mission 13 video
Base Mission
1 point
Live judgedBonus Mission
7 points
Live judgedAdvanced Bonus
13 points
Final judgedScores
Does Not Score
A Pyramid Counts --- and It Is Easier
Read the scoring examples again. A pyramid scores exactly the same as a three-high tower. Two cubes on the bottom, one on top.
This is a final-position mission, so whatever you build has to still be standing when the match ends. A pyramid is far harder to knock over than a tower. Take the easy 13 points.
Use the touch sensor to make your approach repeatable. If your robot can find a wall or a cube by contact instead of by timing, every placement after that starts from a known spot.
Where in your run does the touch sensor help most — finding the cubes, or finding your way back?
| Run | All three stacked? | Still standing at the end? | Points |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
Did the stack fall over on any run? What knocked it — the robot leaving, or the stack itself?
| Mission part | Scored? | Points |
|---|---|---|
| Mission 13 — Advanced Bonus (all three cubes stacked) | 13 | |
| My total | 13 |
Write the condition for each one.
| I want the robot to… | The condition is |
|---|---|
| Drive while the sensor in port 0 is not pressed | |
| Drive while the sensor in port 1 is pressed | |
| Wait until someone presses button A |
Each of these is wrong. Say what happens when you run it.
| Code | What goes wrong |
|---|---|
while (digital(0) = 0) | |
while (digital(0) == 0); | |
ao(); written inside the loop | |
msleep(2000); inside the loop |
Since Project 3, every distance your robot has driven was really a length of time. What does a touch sensor give you that a stopwatch never could?
A touch sensor only tells you something when you are already touching it. Name one thing on the field you would want to stop at, where bumping into it first would be a bad idea.
Your loop asks a question over and over. So far the question has always been about a sensor. What else could a robot count or measure that a loop could watch?
A wall tells you where you are, but only if there is a wall. Most of the field has nothing to bump into.
In Project 11 — Counting Wheel , you point the same loop at a number instead of a switch — and your robot can finally measure how far it has actually gone.
KIPR · Botball Explorer — Discovery Projects · © KISS Institute for Practical Robotics 1997–2026
When you are finished, press the button to turn in your work and save a copy.
KIPR · Botball Explorer · Discovery