4 import radio
# Add this line
8 DISPLAY_ANIMATION_SPEED
= 500
10 np
= neopixel
.NeoPixel(pin0
, NP_COUNT
)
12 radio
.on() # Add this line
19 FIREWORK_COLOURS
= [ (255, 128, 128), (128, 255, 128), (128, 128, 255)
20 , (255, 255, 128), (255, 128, 255), (128, 255, 255)
23 def fade_all(pixels
, first
=0, last
=NP_COUNT
, fade_by
=0.9):
24 for i
in range(first
, last
):
25 fade(pixels
, i
, fade_by
=fade_by
)
28 def fade(pixels
, n
, fade_by
=0.9):
30 pixels
[n
] = (int(r
* fade_by
), int(g
* fade_by
), int(b
* fade_by
))
33 initial_colour
= random
.choice(FIREWORK_COLOURS
)
35 for i
in range(BURST_SIZE
):
36 pixels
[NP_COUNT
- BURST_SIZE
+ i
] = initial_colour
37 pixels
[NP_COUNT
- BURST_SIZE
- i
] = initial_colour
38 fade_all( pixels
, fade_by
=0.95
39 , first
=(NP_COUNT
- BURST_SIZE
- i
)
40 , last
= (NP_COUNT
- BURST_SIZE
+ 1)
44 fade_all(pixels
, first
=(NP_COUNT
- 2 * BURST_SIZE
))
47 for n
in range(NP_COUNT
):
51 display
.show(Image
.DIAMOND
)
54 def shoot_firework(pixels
):
55 display
.show(Image
.ARROW_S
)
56 for pixel
in range(NP_COUNT
- BURST_SIZE
):
65 radio
.send('fire') # Add this line
74 last_gesture
= accelerometer
.current_gesture()
77 gesture
= accelerometer
.current_gesture()
78 if gesture
!= last_gesture
or button_a
.is_pressed():
81 last_gesture
= gesture
82 elif radio_timer
> 0 and radio_timer
== display_timer
:
85 last_gesture
= gesture
88 display_timer
= (display_timer
+ 1) % DISPLAY_ANIMATION_SPEED
89 if display_timer
> (DISPLAY_ANIMATION_SPEED
/ 2):
90 display
.show(Image
.DIAMOND_SMALL
)
92 display
.show(Image
.DIAMOND
)
93 received
= radio
.receive()
94 if received
== 'fire' and random
.randrange(5) == 0:
95 radio_timer
= (display_timer
+ random
.randint(50, 350)) % DISPLAY_ANIMATION_SPEED