4 # Some constants to identify each LED
12 ALL
= 1+2+4+8+16+32+64
15 tree
.setup() # you must always call setup() first!
17 # Two ways of randomly illuminating LEDs (they do the
18 # same thing but Way 1 is easier to understand whilst
19 # Way 2 is a shorter piece of code).
22 for i
in range(100): # repeat 100 times
23 random_led
= random
.randint(0, 6)
24 if (random_led
== 0): tree
.leds_on_and_wait(L0
, 0.2) # D0 on for 0.2s
25 elif (random_led
== 1): tree
.leds_on_and_wait(L1
, 0.2) # D1 on for 0.2s
26 elif (random_led
== 2): tree
.leds_on_and_wait(L2
, 0.2) # D2 on for 0.2s
27 elif (random_led
== 3): tree
.leds_on_and_wait(L3
, 0.2) # D3 on for 0.2s
28 elif (random_led
== 4): tree
.leds_on_and_wait(L4
, 0.2) # D4 on for 0.2s
29 elif (random_led
== 5): tree
.leds_on_and_wait(L5
, 0.2) # D5 on for 0.2s
30 elif (random_led
== 6): tree
.leds_on_and_wait(L6
, 0.2) # D6 on for 0.2s
33 for i
in range(100): # repeat 100 times
34 random_led
= random
.randint(0, 6)
35 tree
.leds_on_and_wait(1<<random_led
, 0.5) # randomly selected LED on for 0.2s
38 tree
.all_leds_off() # extinguish all LEDs
41 tree
.cleanup() # call cleanup() at the end