-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
74 lines (54 loc) · 2.3 KB
/
__main__.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
import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
import audio_processing
import board
import time
import logging
import neopixel
import sys
import os
#debug = logging.DEBUG
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.DEBUG)
#logging.basicConfig(level=debug, format='%(asctime)s %levelname)s: %(message)s',
# datefmt='%m/%d/%Y %I:%M:%S %p')
#logging.info("Logging level: %d", debug)
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.D18
# The number of NeoPixels
num_pixels = 120
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1, auto_write=False,
pixel_order=ORDER)
def decay(data):
pass
def main():
a = audio_processing.AudioProcessor(num_pixels / 2)
fps = audio_processing.FPS(30)
while True:
try:
group = 0
data = a.update()
# a.print_bars()
for index in range(len(data)):
value = a.mapping(0, a.max_calc_volume / 2, 0, 255, data[index]['max_volume'])
value_f = a.mapping(0, a.max_calc_volume / 2, 0, 255, data[index]['falling_max'])
#for i in range(group, group + 11):
# pixels[i] = (0,int(value_f),int(value_f))
#pixels[int(a.mapping(0, 120, 120, 0, index * 3))] = (int(value_f * mod), int(value), int(value_f))
red = a.mapping(0, a.max_calc_volume, 0, 1, index)
opp_index = int(a.mapping(0, 59, 119, 60, index))
pixels[index] = (int(value_f * red), int(0), int(value_f))
pixels[opp_index] = (int(value_f * red), int(0), int(value_f))
pixels.show()
fps.maintain()
except KeyboardInterrupt:
pixels.fill((0, 0, 0))
a.run = False
sys.exit()
if __name__ == "__main__":
main()