comparison examples/basic_button/render.cpp @ 301:e4392164b458 prerelease

RENAMED BeagleRT to Bela AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, scripts probably not working
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 14:34:41 +0100
parents dbeed520b014
children 1feb9c23ac57
comparison
equal deleted inserted replaced
300:dbeed520b014 301:e4392164b458
2 * 2 *
3 * Andrew McPherson and Victor Zappi 3 * Andrew McPherson and Victor Zappi
4 * Queen Mary, University of London 4 * Queen Mary, University of London
5 */ 5 */
6 6
7 #include <BeagleRT.h> 7 #include <Bela.h>
8 #include <Utilities.h> 8 #include <Utilities.h>
9 #include <cmath> 9 #include <cmath>
10 #include <rtdk.h> 10 #include <rtdk.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 12
17 // userData holds an opaque pointer to a data structure that was passed 17 // userData holds an opaque pointer to a data structure that was passed
18 // in from the call to initAudio(). 18 // in from the call to initAudio().
19 // 19 //
20 // Return true on success; returning false halts the program. 20 // Return true on success; returning false halts the program.
21 21
22 bool setup(BeagleRTContext *context, void *userData) 22 bool setup(BelaContext *context, void *userData)
23 { 23 {
24 pinModeFrame(context, 0, P8_08, INPUT); 24 pinModeFrame(context, 0, P8_08, INPUT);
25 pinModeFrame(context, 0, P8_07, OUTPUT); 25 pinModeFrame(context, 0, P8_07, OUTPUT);
26 return true; 26 return true;
27 } 27 }
37 * - connect the other end of the resistor to both a button and P8_08 37 * - connect the other end of the resistor to both a button and P8_08
38 * - connect the other end of the button to ground. 38 * - connect the other end of the button to ground.
39 * The program will read the button and make the LED blink when the button is pressed. 39 * The program will read the button and make the LED blink when the button is pressed.
40 */ 40 */
41 41
42 void render(BeagleRTContext *context, void *userData) 42 void render(BelaContext *context, void *userData)
43 { 43 {
44 for(unsigned int n=0; n<context->digitalFrames; n++){ 44 for(unsigned int n=0; n<context->digitalFrames; n++){
45 int status=digitalReadFrame(context, 0, P8_08); //read the value of the button 45 int status=digitalReadFrame(context, 0, P8_08); //read the value of the button
46 digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED 46 digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED
47 float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button 47 float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button
52 } 52 }
53 53
54 // cleanup() is called once at the end, after the audio has stopped. 54 // cleanup() is called once at the end, after the audio has stopped.
55 // Release any resources that were allocated in setup(). 55 // Release any resources that were allocated in setup().
56 56
57 void cleanup(BeagleRTContext *context, void *userData) 57 void cleanup(BelaContext *context, void *userData)
58 { 58 {
59 // Nothing to do here 59 // Nothing to do here
60 } 60 }
61 61