-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.py
executable file
·44 lines (31 loc) · 897 Bytes
/
code.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
# Dune
# By Jason & Marcel
import time
import board
import pwmio
import neopixel
STEPS_PER_REVOLUTION = 800
NUMPIXELS = 45
# LED setup
led = pwmio.PWMOut(board.CLK, frequency=20000, duty_cycle=0)
pixels = neopixel.NeoPixel(board.DATA, NUMPIXELS, auto_write=False, pixel_order=(1, 0, 2, 3))
lastTimeChange = 0
currentStep = 0
def calculateBrightness(index):
pos = index / NUMPIXELS
center = (currentStep % STEPS_PER_REVOLUTION) / STEPS_PER_REVOLUTION
x = abs(pos - center)
if x > 0.5:
x = 1 - x
result = (-6 * x + 1) * 255
return int(min(max(result, 0), 255))
while True:
now = time.monotonic()
if (now - lastTimeChange) > 0.02:
currentStep += 1
lastTimeChange = now
for i in range(NUMPIXELS):
brightness = calculateBrightness(i)
pixels[i] = (0, 0, 0, brightness)
pixels.show()
led.duty_cycle = 20000