Noise library and examples for basic FFT and frequency binning
[EVA-2020-02-2.git] / examples / noise-amps-at-freqs.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 amps = noise.get_amplitudes_at_frequency_ranges([
28 (100,200),
29 (500,600),
30 (1000,1200)
31 ])
32 amps = [n * 32 for n in amps]
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, amps[0]), fill=(0, 0, 255))
37 draw.line((0, 0, 0, amps[1]), fill=(0, 255, 0))
38 draw.line((0, 0, 0, amps[2]), fill=(255, 0, 0))
39
40 disp.display(img)
41