# HG changeset patch # User Giulio Moro # Date 1437161018 -3600 # Node ID 0598731d3bef8c6103784f4d8c1c0a09a6419118 # Parent 6bfd95cb574463f0be42a2b54d07d0ea24c5bd69 Added basic_blink diff -r 6bfd95cb5744 -r 0598731d3bef projects/basic_blink/render.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/projects/basic_blink/render.cpp Fri Jul 17 20:23:38 2015 +0100 @@ -0,0 +1,60 @@ + /* + * + * Andrew McPherson and Victor Zappi + * Queen Mary, University of London + */ + +#include +#include +#include +#include + +// setup() is called once before the audio rendering starts. +// Use it to perform any initialisation and allocation which is dependent +// on the period size or sample rate. +// +// userData holds an opaque pointer to a data structure that was passed +// in from the call to initAudio(). +// +// Return true on success; returning false halts the program. + +bool setup(BeagleRTContext *context, void *userData) +{ + return true; +} + +// render() is called regularly at the highest priority by the audio engine. +// Input and output are given from the audio hardware and the other +// ADCs and DACs (if available). If only audio is available, numAnalogFrames +// will be 0. + +void render(BeagleRTContext *context, void *userData) +{ + //connect an LED in series with a 470ohm resistor between P8_07 and ground + static int count=0; //counts elapsed samples + float interval=0.5; //how often to toggle the LED (in seconds) + static int status=GPIO_LOW; + for(unsigned int n=0; ndigitalFrames; n++){ + if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed + count=0; //reset the counter + // status=digitalReadFrame(context, 0, P8_07); + if(status==GPIO_LOW) //toggle the status + status=GPIO_HIGH; + else + status=GPIO_LOW; + pinModeFrame(context, 0, P8_07, OUTPUT); + digitalWriteFrame(context, n, P8_07, status); //write the status to the LED + // rt_printf("there %d\n", context->digital[n]); + } + context->digital[n]=status*0x00010000; + count++; + } +} + +// cleanup() is called once at the end, after the audio has stopped. +// Release any resources that were allocated in setup(). + +void cleanup(BeagleRTContext *context, void *userData) +{ + // Nothing to do here +}