| 455 | } |
| 456 | |
| 457 | void setup() { |
| 458 | Serial.begin(115200); |
| 459 | delay(1000); |
| 460 | |
| 461 | Serial.println("Audio Reactive Visualizations"); |
| 462 | Serial.println("Initializing..."); |
| 463 | Serial.print("Display size: "); |
| 464 | Serial.print(WIDTH); |
| 465 | Serial.print("x"); |
| 466 | Serial.println(HEIGHT); |
| 467 | |
| 468 | // Initialize LEDs |
| 469 | FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); |
| 470 | FastLED.setBrightness(brightness.as_int()); |
| 471 | FastLED.clear(); |
| 472 | FastLED.show(); |
| 473 | |
| 474 | // Set up UI callbacks |
| 475 | brightness.onChanged([](float value) { |
| 476 | FastLED.setBrightness(value); |
| 477 | }); |
| 478 | |
| 479 | // Initialize pitch detection |
| 480 | pitchConfig.sample_rate_hz = SAMPLE_RATE; |
| 481 | pitchEngine = new fl::SoundToMIDIEngine(pitchConfig); // ok bare allocation |
| 482 | pitchEngine->onNoteOn = [](uint8_t note, uint8_t velocity) { |
| 483 | currentMIDINote = note; |
| 484 | currentVelocity = velocity; |
| 485 | noteIsOn = true; |
| 486 | Serial.print("Note ON: "); |
| 487 | Serial.print(note); |
| 488 | Serial.print(" (vel: "); |
| 489 | Serial.print(velocity); |
| 490 | Serial.println(")"); |
| 491 | }; |
| 492 | pitchEngine->onNoteOff = [](uint8_t note) { |
| 493 | noteIsOn = false; |
| 494 | Serial.print("Note OFF: "); |
| 495 | Serial.println(note); |
| 496 | }; |
| 497 | |
| 498 | Serial.println("Setup complete!"); |
| 499 | } |
| 500 | |
| 501 | void loop() { |
| 502 | // Check if audio is enabled |