Mercurial > hg > beaglert
comparison examples/02-Digital/digital-input/render.cpp @ 543:8f8809c77dda prerelease
updated basics, digital, instruments, extras examples
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 13:19:52 +0100 |
parents | 1cec96845a23 |
children |
comparison
equal
deleted
inserted
replaced
542:3016638b4da2 | 543:8f8809c77dda |
---|---|
40 { | 40 { |
41 for(unsigned int n=0; n<context->digitalFrames; n++){ | 41 for(unsigned int n=0; n<context->digitalFrames; n++){ |
42 int status=digitalRead(context, 0, P8_08); //read the value of the button | 42 int status=digitalRead(context, 0, P8_08); //read the value of the button |
43 digitalWriteOnce(context, n, P8_07, status); //write the status to the LED | 43 digitalWriteOnce(context, n, P8_07, status); //write the status to the LED |
44 float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button | 44 float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button |
45 for(unsigned int j = 0; j < context->audioChannels; j++){ | 45 for(unsigned int j = 0; j < context->audioOutChannels; j++){ |
46 audioWrite(context, n, j, out); //write the audio output | 46 audioWrite(context, n, j, out); //write the audio output |
47 } | 47 } |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
73 the button is pressed. This is due to the fact that the LED is set to the same | 73 the button is pressed. This is due to the fact that the LED is set to the same |
74 value read at input P8_08. When the button is not pressed, P8_08 is `HIGH` and so | 74 value read at input P8_08. When the button is not pressed, P8_08 is `HIGH` and so |
75 P8_07 is set to `HIGH` as well, so that the LED conducts and emits light. When | 75 P8_07 is set to `HIGH` as well, so that the LED conducts and emits light. When |
76 the button is pressed, P8_08 goes `LOW` and P8_07 is set to `LOW`, turning off the LED. | 76 the button is pressed, P8_08 goes `LOW` and P8_07 is set to `LOW`, turning off the LED. |
77 | 77 |
78 Note that there are two ways of specifying the digital pin: using the GPIO label (e.g. `P8_07`), or using the digital IO index (e.g. 0) | |
79 | |
78 As an exercise try and change the code so that the LED only turns on when | 80 As an exercise try and change the code so that the LED only turns on when |
79 the button is pressed. | 81 the button is pressed. |
80 */ | 82 */ |
81 | 83 |