Fixed typo
[one-dimensional-fireworks.git] / fireworks2.py
1 from microbit import *
2 import neopixel
3
4 NP_COUNT = 60
5 BURST_SIZE = 10
6
7 np = neopixel.NeoPixel(pin0, NP_COUNT)
8
9 BLUE = (0, 0, 64)
10 RED = (64, 0, 0)
11 OFF = (0, 0, 0)
12
13
14 def reset(pixels):
15 for n in range(NP_COUNT):
16 pixels[n] = OFF
17 pixels[0] = BLUE
18 np.show()
19
20 def shoot_firework(pixels):
21 for pixel in range(NP_COUNT - BURST_SIZE):
22 pixels[pixel] = RED
23 pixels.show()
24 sleep(20)
25 pixels[pixel] = OFF
26 pixels.show()
27
28
29 reset(np)
30 last_gesture = accelerometer.current_gesture() # Add this line
31
32 while True:
33 gesture = accelerometer.current_gesture() # Add this line
34 if gesture != last_gesture or button_a.is_pressed(): # Change this line
35 # set off a firework
36 shoot_firework(np)
37 reset(np)
38 last_gesture = gesture # Add this line