Noise library and examples for basic FFT and frequency binning
[EVA-2020-02-2.git] / examples / noise-profile.py
1 import ST7735
2 from PIL import Image, ImageDraw
3 from enviroplus.noise import Noise
4
5 SAMPLERATE = 16000
6
7 FREQ_LOW = 100.0
8 FREQ_HIGH = 2000.0
9 WIDTH = 100
10
11 noise = Noise()
12
13 disp = ST7735.ST7735(
14 port=0,
15 cs=ST7735.BG_SPI_CS_FRONT,
16 dc=9,
17 backlight=12,
18 rotation=90)
19
20 disp.begin()
21
22 img = Image.new('RGB', (disp.width, disp.height), color=(0, 0, 0))
23 draw = ImageDraw.Draw(img)
24
25
26 while True:
27 low, mid, high, amp = noise.measure()
28 low *= 128
29 mid *= 128
30 high *= 128
31 amp *= 64
32
33 img2 = img.copy()
34 draw.rectangle((0, 0, disp.width, disp.height), (0, 0, 0))
35 img.paste(img2, (1, 0))
36 draw.line((0, 0, 0, amp), fill=(int(low), int(mid), int(high)))
37
38 disp.display(img)
39