Skip to content

5. Event Loop

For each of the tasks below, copy the code into EdPy and follow the instructions.

5.1 Squares

Instructions

Below is the code to move for one side of a square. Use the event loop to make it draw a square indefinitely.

Code - Click to expand
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#-------------Setup----------------

import Ed

Ed.EdisonVersion = Ed.V3

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------

Ed.Drive(Ed.FORWARD, Ed.SPEED_3, 10)
Ed.Drive(Ed.SPIN_RIGHT, Ed.SPEED_3, 90)

5.2 Functions & Loops

Instructions

Using the code from earlier, move the code that creates the sides of the square into a function. Call the function from a loop.

5.3 Beeping

Instructions

Using the code from earlier, add to the code so that the Edison beeps at half second intervals while driving in a square.

5.4 Flashing Lights

Instructions

Using the code from earlier, add to the function so that the LED lights flash every 300 milliseconds.

5.5 Alternative Flashing

Instructions

Using the code from earlier, make the LEDs flash alternately. That is when the left light is turned on, the right is turned off, and vice-versa.

5.6 LED Function

Instructions

Using the code from earlier, put the code that flashes the LEDs into a function and run from the function.