Mercurial > hg > beaglert
comparison projects/basic_button/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 | ad130ecb2def |
| children | ec9425f728bc |
comparison
equal
deleted
inserted
replaced
| 54:d3f869b98147 | 108:3068421c0737 |
|---|---|
| 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 /* basic_button | |
| 32 * - connect an LED in series with a 470ohm resistor between P8_07 and ground. | |
| 33 * - connect a 1k resistor to P9_03 (+3.3V), | |
| 34 * - connect the other end of the resistor to both a button and P8_08 | |
| 35 * - connect the other end of the button to ground. | |
| 36 * The program will read the button and make the LED blink when the button is pressed. | |
| 37 */ | |
| 38 | |
| 39 void render(BeagleRTContext *context, void *userData) | |
| 40 { | |
| 41 for(unsigned int n=0; n<context->digitalFrames; n++){ | |
| 42 pinModeFrame(context, 0, P8_08, INPUT); | |
| 43 int status=digitalReadFrame(context, 0, P8_08); //read the value of the button | |
| 44 pinModeFrame(context, 0, P8_07, OUTPUT); | |
| 45 digitalWriteFrame(context, n, P8_07, status); //write the status to the LED | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 // cleanup() is called once at the end, after the audio has stopped. | |
| 50 // Release any resources that were allocated in setup(). | |
| 51 | |
| 52 void cleanup(BeagleRTContext *context, void *userData) | |
| 53 { | |
| 54 // Nothing to do here | |
| 55 } |
