6. Selection
For each of the tasks below, copy the code into EdPy and follow the instructions.
6.1 Random Beeping
Instructions
Fix the code below. The Edison should generate a random number and beep for the same amount of times as the random number.
Code - Click to expand
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
6.2 Clap-on Clap-off
Instructions
The code below should turn a light on upon a clap, if the lights are off. It should also turn them off on a clap, it the lights are on.
Code - Click to expand
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
6.3 Light Detection
Instructions
Start the Edison driving forward until it drives under a table or similar type of area where the light is less than where it started. When it reaches a dark area, make it go backwards into the light.
6.4 Obstacle Avoidance
Instructions
Have the Edison drive from Point A (Start) to Point B (Finish) with an obstacle in between the points. After completing, add two more obstacles and have the Edison avoid them.

6.5 Obstacle Detection
Instructions
Complete the following steps one at a time, make sure to test your Edison after each step.
Step 1 – Basic movement
- Program Edison to drive forward.
- When it detects an obstacle, it should stop.
Step 2 – Avoid the obstacle
Modify the program so that when an obstacle is detected:
- Edison moves backwards 10 cm
- Turns left
- Then continues driving forward.
- Repeat for each obstacle Edison detects.
Step 3 – Add a visual signal
When Edison detects an obstacle:
- Turn on the LEDs for 1 second
- Then perform the same actions as before (reverse, turn, continue driving).
Step 4 – Make the robot smarter
Instead of always turning left:
- Edison should randomly turn left or right after reversing.
- Then continue driving until another obstacle is detected.