Initial commit
[one-dimensional-fireworks.git] / fireworks3.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 #########################################
15 # Add this function
16 def explode(pixels):
17 initial_colour = (255, 128, 128)
18
19 for i in range(BURST_SIZE):
20 pixels[NP_COUNT - BURST_SIZE + i] = initial_colour
21 pixels[NP_COUNT - BURST_SIZE - i] = initial_colour
22 pixels.show()
23 time.sleep(0.5)
24 # End of function to add
25 #########################################
26
27 def reset(pixels):
28 for n in range(NP_COUNT):
29 pixels[n] = OFF
30 pixels[0] = BLUE
31 np.show()
32
33 def shoot_firework(pixels):
34 for pixel in range(NP_COUNT - BURST_SIZE):
35 pixels[pixel] = RED
36 pixels.show()
37 sleep(20)
38 pixels[pixel] = OFF
39 pixels.show()
40
41
42 reset(np)
43 last_gesture = accelerometer.current_gesture()
44
45 while True:
46 gesture = accelerometer.current_gesture()
47 if gesture != last_gesture or button_a.is_pressed():
48 # set off a firework
49 shoot_firework(np)
50 explode(np) # Add this line
51 reset(np)
52 last_gesture = gesture