2023-04-09 21:17:26 +00:00
|
|
|
#include <Adafruit_CircuitPlayground.h>
|
|
|
|
#include <Adafruit_Circuit_Playground.h>
|
|
|
|
|
|
|
|
uint8_t levels[5][2] = {
|
|
|
|
{ 4, 5 },
|
|
|
|
{ 3, 6 },
|
|
|
|
{ 2, 7 },
|
|
|
|
{ 1, 8 },
|
|
|
|
{ 0, 9 },
|
|
|
|
};
|
|
|
|
|
2023-04-09 21:44:21 +00:00
|
|
|
int pixels = 0;
|
|
|
|
|
2023-04-09 21:17:26 +00:00
|
|
|
#define COLOR_MAX 0xFF0000
|
|
|
|
#define COLOR_MID 0xFFFF00
|
|
|
|
#define COLOR_LOW 0x00FF00
|
|
|
|
|
|
|
|
#define MAX_LOUD 50
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
CircuitPlayground.begin();
|
|
|
|
CircuitPlayground.setBrightness(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
float value = CircuitPlayground.mic.soundPressureLevel(10) - 50;
|
|
|
|
float level_size = MAX_LOUD / 6;
|
|
|
|
if (value < level_size) {
|
2023-04-09 21:44:21 +00:00
|
|
|
smoothing();
|
2023-04-09 21:17:26 +00:00
|
|
|
} else {
|
|
|
|
for (int p = 2; p <= 6; p++) {
|
|
|
|
if (value < level_size * p) {
|
|
|
|
lights(p - 1);
|
2023-04-09 21:44:21 +00:00
|
|
|
pixels = p - 1;
|
2023-04-09 21:17:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(90);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lights(int i) {
|
|
|
|
float color = 0xFFFFFF;
|
|
|
|
if (i == 5) {
|
|
|
|
color = COLOR_MAX;
|
2023-04-09 21:44:21 +00:00
|
|
|
for (int p = 0; p < 10; p++) {
|
|
|
|
CircuitPlayground.setPixelColor(p, color);
|
|
|
|
}
|
2023-04-09 21:17:26 +00:00
|
|
|
} else {
|
2023-04-09 21:44:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-04-09 21:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-04-09 21:44:21 +00:00
|
|
|
|
|
|
|
void smoothing() {
|
|
|
|
CircuitPlayground.setPixelColor(levels[pixels][0], 0x000000);
|
|
|
|
CircuitPlayground.setPixelColor(levels[pixels][1], 0x000000);
|
|
|
|
pixels--;
|
|
|
|
}
|