Mercurial > hg > beaglert
changeset 246:da5ce9876fcc
Improved basic_button project
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 19 Apr 2016 22:22:26 +0100 |
parents | ba0b63625146 |
children | feadb63cff32 |
files | projects/basic_button/render.cpp |
diffstat | 1 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/basic_button/render.cpp Tue Apr 19 13:46:37 2016 +0100 +++ b/projects/basic_button/render.cpp Tue Apr 19 22:22:26 2016 +0100 @@ -1,4 +1,4 @@ - /* +/* * * Andrew McPherson and Victor Zappi * Queen Mary, University of London @@ -8,6 +8,7 @@ #include <Utilities.h> #include <cmath> #include <rtdk.h> +#include <stdlib.h> // setup() is called once before the audio rendering starts. // Use it to perform any initialisation and allocation which is dependent @@ -20,10 +21,8 @@ bool setup(BeagleRTContext *context, void *userData) { - for(unsigned int n=0; n<context->digitalFrames; n++){ - pinModeFrame(context, 0, P8_08, INPUT); - pinModeFrame(context, 0, P8_07, OUTPUT); - } + pinModeFrame(context, 0, P8_08, INPUT); + pinModeFrame(context, 0, P8_07, OUTPUT); return true; } @@ -42,13 +41,14 @@ void render(BeagleRTContext *context, void *userData) { - float sum=0; for(unsigned int n=0; n<context->digitalFrames; n++){ int status=digitalReadFrame(context, 0, P8_08); //read the value of the button - sum += status; - digitalWriteFrame(context, n, P8_07, status); //write the status to the LED + digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED + float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button + for(unsigned int j = 0; j < context->audioChannels; j++){ + audioWriteFrame(context, n, j, out); //write the audio output + } } - rt_printf("status: %f\n", sum); } // cleanup() is called once at the end, after the audio has stopped. @@ -58,3 +58,4 @@ { // Nothing to do here } +