forked from having11/NeoPixel-Emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneopixel_viewer.py
92 lines (81 loc) · 3.36 KB
/
neopixel_viewer.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
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
from emulator_backend import Adafruit_NeoPixel
import time
STRIPE_LENGTH = 8
RING_LENGTH = 16
LED_NUMBER = (STRIPE_LENGTH * 2) + (RING_LENGTH * 2)
LED_BRIGHTNESS = 75
DELAY = 0.05
STRIPE_ONE_START = 0 # 0
RING_ONE_FIRST = STRIPE_LENGTH # 8
RING_ONE_START = STRIPE_LENGTH + 1 # 9
RING_ONE_LAST = RING_ONE_FIRST + (RING_LENGTH // 2) # 16
RING_TWO_FIRST = STRIPE_LENGTH + RING_LENGTH # 24
RING_TWO_START = STRIPE_LENGTH + RING_LENGTH + 1 # 25
RING_TWO_LAST = RING_TWO_FIRST + (RING_LENGTH // 2) # 32
STRIPE_TWO_START = STRIPE_LENGTH + (RING_LENGTH * 2) # 40
def kspowerup(pixels):
# Stripes from bottom to top
for i in range(STRIPE_ONE_START, STRIPE_LENGTH, 1):
pixels.setPixelColor(STRIPE_ONE_START + i,pixels.Color(255, 0, 0))
pixels.setPixelColor(STRIPE_TWO_START + i,pixels.Color(255, 0, 0))
pixels.show()
time.sleep(DELAY)
# First LED in rings
pixels.setPixelColor(RING_ONE_FIRST,pixels.Color(0, 255, 255))
pixels.setPixelColor(RING_TWO_FIRST,pixels.Color(0, 255, 255))
pixels.show()
time.sleep(DELAY)
# Rings on both sides simultanously
ring_one_led = RING_ONE_START
ring_two_led = RING_TWO_START
for i in range((RING_ONE_LAST - RING_ONE_FIRST), 0, -2):
pixels.setPixelColor((ring_one_led),pixels.Color(0, 0, 255))
pixels.setPixelColor((ring_one_led + i),pixels.Color(0, 0, 255))
pixels.setPixelColor((ring_two_led),pixels.Color(0, 0, 255))
pixels.setPixelColor((ring_two_led + i),pixels.Color(0, 0, 255))
pixels.show()
time.sleep(DELAY)
ring_one_led = ring_one_led + 1
ring_two_led = ring_two_led + 1
# Last LED in rings
pixels.setPixelColor(RING_ONE_LAST,pixels.Color(0, 255, 255))
pixels.setPixelColor(RING_TWO_LAST,pixels.Color(0, 255, 255))
pixels.show()
time.sleep(DELAY)
def kspowerdown(pixels):
# Last LED in rings
pixels.setPixelColor(RING_ONE_LAST,pixels.Color(0, 0, 0))
pixels.setPixelColor(RING_TWO_LAST,pixels.Color(0, 0, 0))
pixels.show()
time.sleep(DELAY)
# Rings on both sides simultanously
ring_one_led = RING_ONE_LAST - 1
ring_two_led = RING_TWO_LAST - 1
for i in range(2, (RING_ONE_LAST + RING_ONE_FIRST), 2):
pixels.setPixelColor((ring_one_led),pixels.Color(0, 0, 0))
pixels.setPixelColor((ring_one_led + i),pixels.Color(0, 0, 0))
pixels.setPixelColor((ring_two_led),pixels.Color(0, 0, 0))
pixels.setPixelColor((ring_two_led + i),pixels.Color(0, 0, 0))
pixels.show()
time.sleep(DELAY)
ring_one_led = ring_one_led - 1
ring_two_led = ring_two_led - 1
# First LED in rings
pixels.setPixelColor(RING_ONE_FIRST,pixels.Color(0, 0, 0))
pixels.setPixelColor(RING_TWO_FIRST,pixels.Color(0, 0, 0))
pixels.show()
time.sleep(DELAY)
# Stripes from top to bottom
for i in range(STRIPE_LENGTH -1, -1, -1):
pixels.setPixelColor(STRIPE_ONE_START + i,pixels.Color(0, 0, 0))
pixels.setPixelColor(STRIPE_TWO_START + i,pixels.Color(0, 0, 0))
pixels.show()
time.sleep(DELAY)
time.sleep(DELAY)
pixels = Adafruit_NeoPixel(LED_NUMBER,6,"NEO_GRB + NEO_KHZ800")
pixels.begin()
pixels.setBrightness(LED_BRIGHTNESS)
pixels.clear()
kspowerup(pixels)
kspowerdown(pixels)