smoothing and other nice things
This commit is contained in:
parent
1735a1df5e
commit
0e8b950676
|
@ -9,6 +9,8 @@ uint8_t levels[5][2] = {
|
|||
{ 0, 9 },
|
||||
};
|
||||
|
||||
int pixels = 0;
|
||||
|
||||
#define COLOR_MAX 0xFF0000
|
||||
#define COLOR_MID 0xFFFF00
|
||||
#define COLOR_LOW 0x00FF00
|
||||
|
@ -25,11 +27,12 @@ void loop() {
|
|||
float value = CircuitPlayground.mic.soundPressureLevel(10) - 50;
|
||||
float level_size = MAX_LOUD / 6;
|
||||
if (value < level_size) {
|
||||
CircuitPlayground.clearPixels();
|
||||
smoothing();
|
||||
} else {
|
||||
for (int p = 2; p <= 6; p++) {
|
||||
if (value < level_size * p) {
|
||||
lights(p - 1);
|
||||
pixels = p - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -40,23 +43,32 @@ void loop() {
|
|||
|
||||
void lights(int i) {
|
||||
float color = 0xFFFFFF;
|
||||
|
||||
if (i == 5) {
|
||||
color = COLOR_MAX;
|
||||
} else if (i > 2) {
|
||||
color = COLOR_MID;
|
||||
for (int p = 0; p < 10; p++) {
|
||||
CircuitPlayground.setPixelColor(p, color);
|
||||
}
|
||||
} else {
|
||||
color = COLOR_LOW;
|
||||
}
|
||||
|
||||
for (int p = 0; p <= 5; p++) {
|
||||
if (p < i) {
|
||||
CircuitPlayground.setPixelColor(levels[p][0], color);
|
||||
CircuitPlayground.setPixelColor(levels[p][1], color);
|
||||
} else {
|
||||
CircuitPlayground.setPixelColor(levels[p][0], 0x000000);
|
||||
CircuitPlayground.setPixelColor(levels[p][1], 0x000000);
|
||||
for (int p = 0; p <= 5; p++) {
|
||||
if (p < i) {
|
||||
if (p > 1) {
|
||||
color = COLOR_MID;
|
||||
} else {
|
||||
color = COLOR_LOW;
|
||||
}
|
||||
CircuitPlayground.setPixelColor(levels[p][0], color);
|
||||
CircuitPlayground.setPixelColor(levels[p][1], color);
|
||||
} 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--;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue