Week 4 - Section 2 - Shape up

3. Chapter 12.3 - Flash Clap

Professional programmers usually plan out their code before diving in to coding. One way programmers organize their code is by using flowchart diagrams which chart the ‘flow’ of the program from top to bottom.

In a flowchart, the program is represented as a series of shapes representing processes, inputs/outputs and decision. These shapes are connected by arrows that show how the program flows. The words inside the shapes can often be one-word summaries of the process or decision. The idea of a flowchart is to summarize graphically what is happening in the underlying code without revealing all the detail.

There is always a start and usually an end of the program which are both inside an Oval shape called a terminator. A rectangle represents a process or action and a diamond represents a decision point. Inputs or outputs are represented by a parallelogram shape. These are the basic shapes in a flowchart although you can create much more complicated flowcharts with additional shapes.

An example flowchart summarizing the program for the Edison robot waiting for a clap before flashing its left LED is shown below.


The above flowchart corresponds to the following code.


import Ed

Ed.EdisonVersion = Ed.V2

Ed.DistanceUnits = Ed.CM

#--------Your code below-----------

while True:
    if Ed.ReadClapSensor() == Ed.CLAP_DETECTED:
        Ed.TimeWait(50, Ed.TIME_MILLISECONDS)
        Ed.TimeWait(50, Ed.TIME_MILLISECONDS)

You can find the code here

What is the purpose of the TimeWait() function calls in the code? What would happen if we didn’t have them?

Can you make the robot light up both the LEDs when you clap?