-
Notifications
You must be signed in to change notification settings - Fork 0
/
police-lights.py
83 lines (64 loc) · 2.04 KB
/
police-lights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#-----------------------------------------------------------------------------#
# Police Lights
#
# Micropython code for Raspberry Pi Pico w
#
# File : police-lights.py
# Source : https://github.com/RPiSpy/pi-pico
#
# Desc : Police style light pattern with two neopixels
# Hardware : Pi Pico or Pi Pico W
# 2 WS2812 NeoPixels
# Software : Requires neopixel.py
#
# Author : Matt Hawkins
# Website : https://www.raspberrypi-spy.co.uk/
#-----------------------------------------------------------------------------#
import time
from neopixel import Neopixel
# NeoPixel settings
NEOPIXEL_GPIO = 26
NEOPIXEL_BRIGHTNESS_LOW = 1
NEOPIXEL_BRIGHTNESS_HIGH = 100
COLOUR_BLUE = (0,0,255)
COLOUR_RED = (255, 0, 0)
pixels = Neopixel(2, 0, NEOPIXEL_GPIO, "GRB")
brightness_l = NEOPIXEL_BRIGHTNESS_LOW
brightness_h = NEOPIXEL_BRIGHTNESS_HIGH
# Quick flash delay (ms)
delay_short = 35
# Delay between switching pixels (ms)
delay_long = 300
# Set starting colours of neopixels
colour_p1 = COLOUR_RED
colour_p2 = COLOUR_BLUE
while True:
# Quick flash Pixel #1
for x in range(0,3):
time.sleep_ms(delay_short)
pixels.set_pixel(0, colour_p1, brightness_l)
pixels.set_pixel(1, colour_p2, brightness_h)
pixels.show()
time.sleep_ms(delay_short)
pixels.set_pixel(0, colour_p1, brightness_l)
pixels.set_pixel(1, colour_p2, brightness_l)
pixels.show()
time.sleep_ms(delay_long)
# Quick Flash Pixel #2
for x in range(0,3):
time.sleep_ms(delay_short)
pixels.set_pixel(0, colour_p1, brightness_h)
pixels.set_pixel(1, colour_p2, brightness_l)
pixels.show()
time.sleep_ms(delay_short)
pixels.set_pixel(0, colour_p1, brightness_l)
pixels.set_pixel(1, colour_p2, brightness_l)
pixels.show()
time.sleep_ms(delay_long)
# Swap pixel colours
if colour_p1 == COLOUR_RED:
colour_p1 = COLOUR_BLUE
colour_p2 = COLOUR_RED
else:
colour_p1 = COLOUR_RED
colour_p2 = COLOUR_BLUE