#include #include uint8_t levels[5][2] = { { 4, 5 }, { 3, 6 }, { 2, 7 }, { 1, 8 }, { 0, 9 }, }; int pixels = 0; #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) { smoothing(); } else { for (int p = 2; p <= 6; p++) { if (value < level_size * p) { lights(p - 1); pixels = p - 1; break; } } } delay(90); } void lights(int i) { float color = 0xFFFFFF; if (i == 5) { color = COLOR_MAX; for (int p = 0; p < 10; p++) { CircuitPlayground.setPixelColor(p, color); } } else { 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--; }