smoothing and other nice things

This commit is contained in:
tess 2023-04-09 23:44:21 +02:00
parent 1735a1df5e
commit 0e8b950676
1 changed files with 26 additions and 14 deletions

View File

@ -9,6 +9,8 @@ uint8_t levels[5][2] = {
{ 0, 9 }, { 0, 9 },
}; };
int pixels = 0;
#define COLOR_MAX 0xFF0000 #define COLOR_MAX 0xFF0000
#define COLOR_MID 0xFFFF00 #define COLOR_MID 0xFFFF00
#define COLOR_LOW 0x00FF00 #define COLOR_LOW 0x00FF00
@ -25,11 +27,12 @@ void loop() {
float value = CircuitPlayground.mic.soundPressureLevel(10) - 50; float value = CircuitPlayground.mic.soundPressureLevel(10) - 50;
float level_size = MAX_LOUD / 6; float level_size = MAX_LOUD / 6;
if (value < level_size) { if (value < level_size) {
CircuitPlayground.clearPixels(); smoothing();
} else { } else {
for (int p = 2; p <= 6; p++) { for (int p = 2; p <= 6; p++) {
if (value < level_size * p) { if (value < level_size * p) {
lights(p - 1); lights(p - 1);
pixels = p - 1;
break; break;
} }
} }
@ -40,23 +43,32 @@ void loop() {
void lights(int i) { void lights(int i) {
float color = 0xFFFFFF; float color = 0xFFFFFF;
if (i == 5) { if (i == 5) {
color = COLOR_MAX; color = COLOR_MAX;
} else if (i > 2) { for (int p = 0; p < 10; p++) {
color = COLOR_MID; CircuitPlayground.setPixelColor(p, color);
}
} else { } else {
color = COLOR_LOW; for (int p = 0; p <= 5; p++) {
} if (p < i) {
if (p > 1) {
for (int p = 0; p <= 5; p++) { color = COLOR_MID;
if (p < i) { } else {
CircuitPlayground.setPixelColor(levels[p][0], color); color = COLOR_LOW;
CircuitPlayground.setPixelColor(levels[p][1], color); }
} else { CircuitPlayground.setPixelColor(levels[p][0], color);
CircuitPlayground.setPixelColor(levels[p][0], 0x000000); CircuitPlayground.setPixelColor(levels[p][1], color);
CircuitPlayground.setPixelColor(levels[p][1], 0x000000); } else {
CircuitPlayground.setPixelColor(levels[p][0], 0x000000);
CircuitPlayground.setPixelColor(levels[p][1], 0x000000);
}
} }
} }
} }
void smoothing() {
CircuitPlayground.setPixelColor(levels[pixels][0], 0x000000);
CircuitPlayground.setPixelColor(levels[pixels][1], 0x000000);
pixels--;
}