initial commit

This commit is contained in:
tess 2023-04-09 23:17:26 +02:00
commit 54c0086f6c
1 changed files with 62 additions and 0 deletions

62
volume_indicator.ino Normal file
View File

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