Mercurial > hg > beaglert
diff examples/basic_analog_input/render.cpp @ 372:db2fe4e1b88e prerelease
Doxygen content added to each example render.cpp.
References to AnalogReadFrame etc. removed from doxygen content.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Thu, 09 Jun 2016 18:16:05 +0100 |
parents | 1feb9c23ac57 |
children | 9dc5a0ccad25 |
line wrap: on
line diff
--- a/examples/basic_analog_input/render.cpp Thu Jun 09 17:31:44 2016 +0100 +++ b/examples/basic_analog_input/render.cpp Thu Jun 09 18:16:05 2016 +0100 @@ -1,3 +1,12 @@ +/* + ____ _____ _ _ +| __ )| ____| | / \ +| _ \| _| | | / _ \ +| |_) | |___| |___ / ___ \ +|____/|_____|_____/_/ \_\.io + + */ + /* * render.cpp * @@ -5,6 +14,34 @@ * Author: parallels */ +/** +\example 3_analog_input + +Connecting potentiometers +------------------------- + +This sketch produces a sine tone, the frequency and amplitude of which are +affected by data received on the analog pins. Before looping through each audio +frame, we declare a value for the frequency and amplitude of our sine tone +(line 55); we adjust these values by taking in data from analog sensors +(for example potentiometers) with `analogRead()`. + +- connect a 10K pot to 3.3V and GND on its 1st and 3rd pins. +- connect the 2nd middle pin of the pot to analogIn 0. +- connect another 10K pot in the same way but with the middle pin connected to analogIn 1. + +The important thing to notice is that audio is sampled twice as often as analog +data. The audio sampling rate is 44.1kHz (44100 frames per second) and the +analog sampling rate is 22.05kHz (22050 frames per second). On line 62 you might +notice that we are processing the analog data and updating frequency and +amplitude only on every second audio sample, since the analog sampling rate is +half that of the audio. + +Note that the pin numbers are stored in the variables `gAnalogInputFrequency` and +`gAnalogInputAmplitude`. These are declared in the main.cpp file; if you look in +that file you will see that they have the values of 0 and 1. Bear in mind that +these are analog input pins which is a specific header! +*/ #include <Bela.h> #include <Utilities.h>