Mercurial > hg > beaglert
comparison projects/basic_blink/render.cpp @ 74:0598731d3bef
Added basic_blink
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 17 Jul 2015 20:23:38 +0100 |
parents | |
children | 8bd351ca8b46 |
comparison
equal
deleted
inserted
replaced
73:6bfd95cb5744 | 74:0598731d3bef |
---|---|
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 | |
12 // setup() is called once before the audio rendering starts. | |
13 // Use it to perform any initialisation and allocation which is dependent | |
14 // on the period size or sample rate. | |
15 // | |
16 // userData holds an opaque pointer to a data structure that was passed | |
17 // in from the call to initAudio(). | |
18 // | |
19 // Return true on success; returning false halts the program. | |
20 | |
21 bool setup(BeagleRTContext *context, void *userData) | |
22 { | |
23 return true; | |
24 } | |
25 | |
26 // render() is called regularly at the highest priority by the audio engine. | |
27 // Input and output are given from the audio hardware and the other | |
28 // ADCs and DACs (if available). If only audio is available, numAnalogFrames | |
29 // will be 0. | |
30 | |
31 void render(BeagleRTContext *context, void *userData) | |
32 { | |
33 //connect an LED in series with a 470ohm resistor between P8_07 and ground | |
34 static int count=0; //counts elapsed samples | |
35 float interval=0.5; //how often to toggle the LED (in seconds) | |
36 static int status=GPIO_LOW; | |
37 for(unsigned int n=0; n<context->digitalFrames; n++){ | |
38 if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed | |
39 count=0; //reset the counter | |
40 // status=digitalReadFrame(context, 0, P8_07); | |
41 if(status==GPIO_LOW) //toggle the status | |
42 status=GPIO_HIGH; | |
43 else | |
44 status=GPIO_LOW; | |
45 pinModeFrame(context, 0, P8_07, OUTPUT); | |
46 digitalWriteFrame(context, n, P8_07, status); //write the status to the LED | |
47 // rt_printf("there %d\n", context->digital[n]); | |
48 } | |
49 context->digital[n]=status*0x00010000; | |
50 count++; | |
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 } |