7. Loops with Conditions
7.1 Obstacle Avoidance
Instructions
- Start the Edison driving forward. When it detects an obstacle, make it move backwards
10cmand turn180 degrees. Then make it stop. - After moving backwards and turning, the Edison should keep driving again until it detects another obstacle where it will move backwards and turn again. Repeat this until the Edison has detected an obstacle on its fifth time, then it must stop.
7.2 Random Movements
Instructions
Generate 5 random numbers between 1 and 4 (inclusive). Make the Edison perform a different movement / action based on the generated number:
| Random Number | Movement / Action |
|---|---|
| 1 | Move forwards 10cm |
| 2 | Move backwards 10cm |
| 3 | Spin left |
| 4 | Spin right |
7.3 Random Guessing
Instructions
Make a number guessing game. Generate a number between 1 and 10. Use the triangle and round buttons for input.
- The Edison will generate a random number between
1and10. - The user will press the
trianglebutton a number of times to guess the number. - Pressing the
roundbutton will end their guess. - If the user is
correct, beep the Edisontwice. - If the user is
incorrect, beep the Edisononce.
7.4 Random Beeping
Instructions
Using the code you wrote from the previous task, use Ed.PlayMyBeep(8000) to beep the amount of times of the randomly generated number. You must use a while loop for this.