diff projects/level_meter/render.cpp @ 284:7bfb25a2e158 Doxy prerelease

Merge
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 15:53:24 +0100
parents 8d80eda512cd
children
line wrap: on
line diff
--- a/projects/level_meter/render.cpp	Tue May 17 15:40:16 2016 +0100
+++ b/projects/level_meter/render.cpp	Tue May 17 15:53:24 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