Fix combined.py indentation for Python 3.x
[EVA-2020-02-2.git] / examples / noise-profile.py
... / ...
CommitLineData
1import ST7735
2from PIL import Image, ImageDraw
3from enviroplus.noise import Noise
4
5print("""noise-profile.py - Get a simple noise profile.
6
7This example grabs a basic 3-bin noise profile of low, medium and high frequency noise, plotting the noise characteristics as coloured bars.
8
9Press Ctrl+C to exit!
10
11""")
12
13noise = Noise()
14
15disp = ST7735.ST7735(
16 port=0,
17 cs=ST7735.BG_SPI_CS_FRONT,
18 dc=9,
19 backlight=12,
20 rotation=90)
21
22disp.begin()
23
24img = Image.new('RGB', (disp.width, disp.height), color=(0, 0, 0))
25draw = ImageDraw.Draw(img)
26
27
28while True:
29 low, mid, high, amp = noise.get_noise_profile()
30 low *= 128
31 mid *= 128
32 high *= 128
33 amp *= 64
34
35 img2 = img.copy()
36 draw.rectangle((0, 0, disp.width, disp.height), (0, 0, 0))
37 img.paste(img2, (1, 0))
38 draw.line((0, 0, 0, amp), fill=(int(low), int(mid), int(high)))
39
40 disp.display(img)