Files
mikeandClaude Opus 5.5 55b94475a5 Firmware, iOS-App und Gehäuse für den 5x5x5-LED-Würfel
ESP32-S3-Firmware mit 18 Effekten, Mikrofon (Klatschen, Beat, Spektrum)
und REST-API, Testprogramme, SwiftUI-Fernbedienung und OpenSCAD-Sockel.
Die WLAN-Zugangsdaten (secrets.h) sind nicht enthalten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 15:00:43 +01:00

67 lines
2.2 KiB
Arduino

// Hardwaretest: Mikrofon (MAX9814 OUT an GPIO 4) und zwei Taster (GPIO 6/7 gegen GND).
// Serielle Ausgabe; der Würfel zeigt die Lautstärke als Etagen von unten.
// Farbe: grün = kein Taster, blau = Taster 1, rot = Taster 2, lila = beide.
#include <FastLED.h>
#define DATA_PIN 10
#define NUM_LEDS 125
#define MIC_PIN 4
#define BTN1_PIN 6
#define BTN2_PIN 7
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(115200);
pinMode(BTN1_PIN, INPUT_PULLUP);
pinMode(BTN2_PIN, INPUT_PULLUP);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(32);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
delay(1500);
Serial.printf("Hardwaretest: Mikrofon GPIO %u, Taster GPIO %u und %u\n", MIC_PIN, BTN1_PIN, BTN2_PIN);
Serial.print("ADC-Scan (mV):");
for (uint8_t pin = 0; pin <= 4; pin++) Serial.printf(" GPIO%u=%lu", pin, analogReadMilliVolts(pin));
Serial.println();
}
void loop() {
static uint32_t lastPrint = 0;
static uint16_t maxPP = 0;
static bool last1 = false, last2 = false;
// 20 ms lang so schnell wie möglich messen: Mittelwert und Spitze-Spitze
uint16_t lo = 65535, hi = 0;
uint32_t sum = 0, n = 0, start = millis();
while (millis() - start < 20) {
uint16_t v = analogReadMilliVolts(MIC_PIN);
lo = min(lo, v);
hi = max(hi, v);
sum += v;
n++;
}
uint16_t pp = hi - lo;
maxPP = max(maxPP, pp);
bool b1 = digitalRead(BTN1_PIN) == LOW, b2 = digitalRead(BTN2_PIN) == LOW;
if (b1 != last1) Serial.printf(">>> Taster 1 %s\n", b1 ? "gedrueckt" : "losgelassen");
if (b2 != last2) Serial.printf(">>> Taster 2 %s\n", b2 ? "gedrueckt" : "losgelassen");
last1 = b1;
last2 = b2;
if (millis() - lastPrint >= 250) {
lastPrint = millis();
Serial.printf("t=%6.1fs Mikro: Mitte %4lu mV, Pegel %4u mV (%lu Messungen) | T1 %s T2 %s\n",
millis() / 1000.0, sum / n, maxPP, n, b1 ? "GEDRUECKT" : "offen", b2 ? "GEDRUECKT" : "offen");
maxPP = 0;
}
// Lautstärke als Säule: 200 mV Spitze-Spitze pro Etage
CRGB color = b1 && b2 ? CRGB::Purple : b1 ? CRGB::Blue : b2 ? CRGB::Red : CRGB::Green;
uint8_t layers = min(5, (pp + 100) / 200);
FastLED.clear();
fill_solid(leds, layers * 25, color);
FastLED.show();
}