// 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 #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(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(); }