comparison examples/basic_button/render.cpp @ 300:dbeed520b014 prerelease

Renamed projects to examples
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 13:58:20 +0100
parents projects/basic_button/render.cpp@da5ce9876fcc
children e4392164b458
comparison
equal deleted inserted replaced
297:a3d83ebdf49b 300:dbeed520b014
1 /*
2 *
3 * Andrew McPherson and Victor Zappi
4 * Queen Mary, University of London
5 */
6
7 #include <BeagleRT.h>
8 #include <Utilities.h>
9 #include <cmath>
10 #include <rtdk.h>
11 #include <stdlib.h>
12
13 // setup() is called once before the audio rendering starts.
14 // Use it to perform any initialisation and allocation which is dependent
15 // on the period size or sample rate.
16 //
17 // userData holds an opaque pointer to a data structure that was passed
18 // in from the call to initAudio().
19 //
20 // Return true on success; returning false halts the program.
21
22 bool setup(BeagleRTContext *context, void *userData)
23 {
24 pinModeFrame(context, 0, P8_08, INPUT);
25 pinModeFrame(context, 0, P8_07, OUTPUT);
26 return true;
27 }
28
29 // render() is called regularly at the highest priority by the audio engine.
30 // Input and output are given from the audio hardware and the other
31 // ADCs and DACs (if available). If only audio is available, numAnalogFrames
32 // will be 0.
33
34 /* basic_button
35 * - connect an LED in series with a 470ohm resistor between P8_07 and ground.
36 * - connect a 1k resistor to P9_03 (+3.3V),
37 * - connect the other end of the resistor to both a button and P8_08
38 * - connect the other end of the button to ground.
39 * The program will read the button and make the LED blink when the button is pressed.
40 */
41
42 void render(BeagleRTContext *context, void *userData)
43 {
44 for(unsigned int n=0; n<context->digitalFrames; n++){
45 int status=digitalReadFrame(context, 0, P8_08); //read the value of the button
46 digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED
47 float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button
48 for(unsigned int j = 0; j < context->audioChannels; j++){
49 audioWriteFrame(context, n, j, out); //write the audio output
50 }
51 }
52 }
53
54 // cleanup() is called once at the end, after the audio has stopped.
55 // Release any resources that were allocated in setup().
56
57 void cleanup(BeagleRTContext *context, void *userData)
58 {
59 // Nothing to do here
60 }
61