comparison projects/basic_blink/render.cpp @ 75:8bd351ca8b46

Fixed direction in setPinMode functions, updated and fixed basic_blink
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 17 Jul 2015 20:59:43 +0100
parents 0598731d3bef
children ff0f776415e4
comparison
equal deleted inserted replaced
74:0598731d3bef 75:8bd351ca8b46
1 /*
2 *
3 * Andrew McPherson and Victor Zappi
4 * Queen Mary, University of London
5 */
6
7 #include <BeagleRT.h> 1 #include <BeagleRT.h>
8 #include <Utilities.h> 2 #include <Utilities.h>
9 #include <cmath> 3 #include <cmath>
10 #include <rtdk.h> 4 #include <rtdk.h>
11 5
26 // render() is called regularly at the highest priority by the audio engine. 20 // 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 21 // Input and output are given from the audio hardware and the other
28 // ADCs and DACs (if available). If only audio is available, numAnalogFrames 22 // ADCs and DACs (if available). If only audio is available, numAnalogFrames
29 // will be 0. 23 // will be 0.
30 24
25 /* basic_blink
26 * Connect an LED in series with a 470ohm resistor between P8_07 and ground.
27 * The LED will blink every @interval seconds.
28 */
29
31 void render(BeagleRTContext *context, void *userData) 30 void render(BeagleRTContext *context, void *userData)
32 { 31 {
33 //connect an LED in series with a 470ohm resistor between P8_07 and ground
34 static int count=0; //counts elapsed samples 32 static int count=0; //counts elapsed samples
35 float interval=0.5; //how often to toggle the LED (in seconds) 33 float interval=0.5; //how often to toggle the LED (in seconds)
36 static int status=GPIO_LOW; 34 static int status=GPIO_LOW;
37 for(unsigned int n=0; n<context->digitalFrames; n++){ 35 for(unsigned int n=0; n<context->digitalFrames; n++){
38 if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed 36 if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed
40 // status=digitalReadFrame(context, 0, P8_07); 38 // status=digitalReadFrame(context, 0, P8_07);
41 if(status==GPIO_LOW) //toggle the status 39 if(status==GPIO_LOW) //toggle the status
42 status=GPIO_HIGH; 40 status=GPIO_HIGH;
43 else 41 else
44 status=GPIO_LOW; 42 status=GPIO_LOW;
45 pinModeFrame(context, 0, P8_07, OUTPUT); 43 pinModeFrame(context, n, P8_07, OUTPUT);
46 digitalWriteFrame(context, n, P8_07, status); //write the status to the LED 44 digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED
47 // rt_printf("there %d\n", context->digital[n]);
48 } 45 }
49 context->digital[n]=status*0x00010000;
50 count++; 46 count++;
51 } 47 }
52 } 48 }
53 49
54 // cleanup() is called once at the end, after the audio has stopped. 50 // cleanup() is called once at the end, after the audio has stopped.