robert@464: /* robert@464: ____ _____ _ _ robert@464: | __ )| ____| | / \ robert@464: | _ \| _| | | / _ \ robert@464: | |_) | |___| |___ / ___ \ robert@464: |____/|_____|_____/_/ \_\ robert@464: robert@464: The platform for ultra-low latency audio and sensor processing robert@464: robert@464: http://bela.io robert@464: robert@464: A project of the Augmented Instruments Laboratory within the robert@464: Centre for Digital Music at Queen Mary University of London. robert@464: http://www.eecs.qmul.ac.uk/~andrewm robert@464: robert@464: (c) 2016 Augmented Instruments Laboratory: Andrew McPherson, robert@464: Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack, robert@464: Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved. robert@464: robert@464: The Bela software is distributed under the GNU Lesser General Public License robert@464: (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt robert@464: */ robert@464: robert@464: robert@464: #include robert@464: #include robert@464: #include robert@464: #include robert@464: robert@464: robert@464: bool setup(BelaContext *context, void *userData) robert@464: { robert@464: pinMode(context, 0, P8_08, INPUT); robert@464: pinMode(context, 0, P8_07, OUTPUT); robert@464: return true; robert@464: } robert@464: robert@464: robert@464: void render(BelaContext *context, void *userData) robert@464: { robert@464: for(unsigned int n=0; ndigitalFrames; n++){ robert@464: int status=digitalRead(context, 0, P8_08); //read the value of the button robert@464: digitalWriteOnce(context, n, P8_07, status); //write the status to the LED robert@464: float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button robert@464: for(unsigned int j = 0; j < context->audioChannels; j++){ robert@464: audioWrite(context, n, j, out); //write the audio output robert@464: } robert@464: } robert@464: } robert@464: robert@464: robert@464: void cleanup(BelaContext *context, void *userData) robert@464: { robert@464: // Nothing to do here robert@464: } robert@464: robert@464: robert@464: /** robert@500: \example digital-input/render.cpp robert@464: robert@464: Switching an LED on and off robert@464: --------------------------- robert@464: robert@464: This example brings together digital input and digital output. The program will read robert@464: a button and turn the LED on and off according to the state of the button. robert@464: robert@464: - connect an LED in series with a 470ohm resistor between P8_07 and ground. robert@464: - connect a 1k resistor to P9_03 (+3.3V), robert@464: - connect the other end of the resistor to both a button and P8_08 robert@464: - connect the other end of the button to ground. robert@464: robert@464: You will notice that the LED will normally stay on and will turn off as long as robert@464: the button is pressed. This is due to the fact that the LED is set to the same robert@464: value read at input P8_08. When the button is not pressed, P8_08 is `HIGH` and so robert@464: P8_07 is set to `HIGH` as well, so that the LED conducts and emits light. When robert@464: the button is pressed, P8_08 goes `LOW` and P8_07 is set to `LOW`, turning off the LED. robert@464: robert@464: As an exercise try and change the code so that the LED only turns on when robert@464: the button is pressed. robert@464: */ robert@464: