Mercurial > hg > beaglert
diff projects/level_meter/render.cpp @ 268:8d80eda512cd prerelease
Added new overlay for using PRU0 or PRU1, a script to halt board on button press, and several example projects
author | andrewm |
---|---|
date | Tue, 17 May 2016 14:46:26 +0100 |
parents | 3a5823f7a11f |
children |
line wrap: on
line diff
--- a/projects/level_meter/render.cpp Tue May 17 14:38:03 2016 +0100 +++ b/projects/level_meter/render.cpp Tue May 17 14:46:26 2016 +0100 @@ -21,6 +21,7 @@ // Thresholds for LEDs: set in setup() float gThresholds[NUMBER_OF_SEGMENTS + 1]; +int gSamplesToLight[NUMBER_OF_SEGMENTS]; // High-pass filter on the input float gLastX[2] = {0}; @@ -57,8 +58,10 @@ gThresholds[i] = powf(10.0f, (-1.0 * (NUMBER_OF_SEGMENTS - i)) * .05); } - for(int i = 0; i < NUMBER_OF_SEGMENTS; i++) + for(int i = 0; i < NUMBER_OF_SEGMENTS; i++) { + gSamplesToLight[i] = 0; pinModeFrame(context, 0, i, OUTPUT); + } return true; } @@ -111,9 +114,15 @@ // for the peak level also remains lit. int state = LOW; - if(gAudioLocalLevel > gThresholds[led]) + if(gAudioLocalLevel > gThresholds[led]) { state = HIGH; - else if(gAudioPeakLevel > gThresholds[led] && gAudioPeakLevel <= gThresholds[led + 1]) + gSamplesToLight[led] = 1000; + } + /*else if(gAudioPeakLevel > gThresholds[led] && gAudioPeakLevel <= gThresholds[led + 1]) { + state = HIGH; + gSamplesToLight[led] = 1000; + }*/ + else if(--gSamplesToLight[led] > 0) state = HIGH; // Write LED