X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git/blobdiff_plain/aa747a416652b64a182d6e2594c08e2476d17d76..6c6e55301f85a23a4d393cf5244f0f5ba441e309:/examples/noise-amps-at-freqs.py?ds=sidebyside diff --git a/examples/noise-amps-at-freqs.py b/examples/noise-amps-at-freqs.py old mode 100644 new mode 100755 index 0a8040b..4c14c58 --- a/examples/noise-amps-at-freqs.py +++ b/examples/noise-amps-at-freqs.py @@ -2,20 +2,24 @@ import ST7735 from PIL import Image, ImageDraw from enviroplus.noise import Noise -SAMPLERATE = 16000 +print("""noise-amps-at-freqs.py - Measure amplitude from specific frequency bins -FREQ_LOW = 100.0 -FREQ_HIGH = 2000.0 -WIDTH = 100 +This example retrieves the median amplitude from 3 user-specified frequency ranges and plots them in Blue, Green and Red on the Enviro+ display. + +As you play a continuous rising tone on your phone, you should notice peaks that correspond to the frequency entering each range. + +Press Ctrl+C to exit! + +""") noise = Noise() disp = ST7735.ST7735( - port=0, - cs=ST7735.BG_SPI_CS_FRONT, - dc=9, - backlight=12, - rotation=90) + port=0, + cs=ST7735.BG_SPI_CS_FRONT, + dc=9, + backlight=12, + rotation=90) disp.begin() @@ -25,9 +29,9 @@ draw = ImageDraw.Draw(img) while True: amps = noise.get_amplitudes_at_frequency_ranges([ - (100,200), - (500,600), - (1000,1200) + (100, 200), + (500, 600), + (1000, 1200) ]) amps = [n * 32 for n in amps] img2 = img.copy() @@ -38,4 +42,3 @@ while True: draw.line((0, 0, 0, amps[2]), fill=(255, 0, 0)) disp.display(img) -