User manual

49
For the programme to be universal and easily alterable, we will ow define three variables:
z Number of LEDs
The number of LEDs is automatically adopted from the list
LED by using the
function
len().
w Repetitions
Each pattern is repeated five times by default so that the pattern is better for
better recognize it better detected. This number can be changed as desired, and
is then applies to all patterns.
t Time
This variable indicates how long a flashing LED is turned on. The pause, that
follows will last just as long. The name
t is commonly used in all programming
languages for variables that store time intervals in programs.
The values defined as variables are introduced only here at this point within the program and can be easily
changed. Following these definitions the actual program begins.
print (“Light effects selection"); print ("1 – cyclical chaser")
print ("2 – chase bidirectional"); print ("3 – ascending and descending")
print ("4 – all flashing simultaneously"); print ("5 – all flashing at random")
print (“Ctrl+C exits the program")
These lines will provide the user with an on-screen guidance on which numeric key will display which
pattern.
Fig. 5.3: The program on-screen.
After the selection has been indicated, the main loop of the program will start. We are also using here the
infinite loop
while True:, whicmeh is embedded in the statement try...except.
e = raw_input (“Please select a pattern: ") Right at the start of the loop, the program waits for the
user’s input which then is stored in the variable
e. The function raw_input() adopts the input as plain text,
without evaluating. In contrast,
input(), which are mathematical operations or variable names, are
evaluated on spot. That means that
raw_input() is in most cases therefore the better choice, because you
don’t have to worry about the many events of possible inputs.