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