giuliomoro@301
|
1 #include <Bela.h>
|
giuliomoro@74
|
2 #include <Utilities.h>
|
giuliomoro@74
|
3 #include <cmath>
|
giuliomoro@74
|
4 #include <rtdk.h>
|
giuliomoro@74
|
5
|
giuliomoro@74
|
6 // setup() is called once before the audio rendering starts.
|
giuliomoro@74
|
7 // Use it to perform any initialisation and allocation which is dependent
|
giuliomoro@74
|
8 // on the period size or sample rate.
|
giuliomoro@74
|
9 //
|
giuliomoro@74
|
10 // userData holds an opaque pointer to a data structure that was passed
|
giuliomoro@74
|
11 // in from the call to initAudio().
|
giuliomoro@74
|
12 //
|
giuliomoro@74
|
13 // Return true on success; returning false halts the program.
|
giuliomoro@74
|
14
|
giuliomoro@301
|
15 bool setup(BelaContext *context, void *userData)
|
giuliomoro@74
|
16 {
|
andrewm@310
|
17 pinMode(context, 0, P8_07, OUTPUT);
|
giuliomoro@74
|
18 return true;
|
giuliomoro@74
|
19 }
|
giuliomoro@74
|
20
|
giuliomoro@74
|
21 // render() is called regularly at the highest priority by the audio engine.
|
giuliomoro@74
|
22 // Input and output are given from the audio hardware and the other
|
giuliomoro@74
|
23 // ADCs and DACs (if available). If only audio is available, numAnalogFrames
|
giuliomoro@74
|
24 // will be 0.
|
giuliomoro@74
|
25
|
giuliomoro@75
|
26 /* basic_blink
|
giuliomoro@75
|
27 * Connect an LED in series with a 470ohm resistor between P8_07 and ground.
|
giuliomoro@75
|
28 * The LED will blink every @interval seconds.
|
giuliomoro@75
|
29 */
|
giuliomoro@75
|
30
|
giuliomoro@301
|
31 void render(BelaContext *context, void *userData)
|
giuliomoro@74
|
32 {
|
giuliomoro@74
|
33 static int count=0; //counts elapsed samples
|
giuliomoro@74
|
34 float interval=0.5; //how often to toggle the LED (in seconds)
|
giuliomoro@74
|
35 static int status=GPIO_LOW;
|
giuliomoro@74
|
36 for(unsigned int n=0; n<context->digitalFrames; n++){
|
giuliomoro@74
|
37 if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed
|
giuliomoro@74
|
38 count=0; //reset the counter
|
andrewm@308
|
39 // status=digitalRead(context, 0, P8_07);
|
andrewm@81
|
40 if(status==GPIO_LOW) { //toggle the status
|
andrewm@308
|
41 digitalWrite(context, n, P8_07, status); //write the status to the LED
|
andrewm@81
|
42 status=GPIO_HIGH;
|
andrewm@81
|
43 }
|
andrewm@81
|
44 else {
|
andrewm@308
|
45 digitalWrite(context, n, P8_07, status); //write the status to the LED
|
andrewm@81
|
46 status=GPIO_LOW;
|
andrewm@81
|
47 }
|
giuliomoro@74
|
48 }
|
giuliomoro@74
|
49 count++;
|
giuliomoro@74
|
50 }
|
giuliomoro@74
|
51 }
|
giuliomoro@74
|
52
|
giuliomoro@74
|
53 // cleanup() is called once at the end, after the audio has stopped.
|
giuliomoro@74
|
54 // Release any resources that were allocated in setup().
|
giuliomoro@74
|
55
|
giuliomoro@301
|
56 void cleanup(BelaContext *context, void *userData)
|
giuliomoro@74
|
57 {
|
giuliomoro@74
|
58 // Nothing to do here
|
giuliomoro@74
|
59 }
|