🎨 Mapeo de LEDs con MIDI Clock

Sincroniza tiras WS2812B al BPM de tu DAW usando Arduino y WebMIDI

Simulación de LEDs

MIDI: Desconectado

🛠️ Componentes Necesarios

📟 Código Arduino

#include <FastLED.h> #define LED_PIN 6 #define NUM_LEDS 60 #define BRIGHTNESS 64 CRGB leds[NUM_LEDS]; int bpm = 120; unsigned long lastBeat = 0; int currentPattern = 0; void setup() { FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(BRIGHTNESS); Serial.begin(115200); Serial.println("LED MIDI Controller Ready"); } void loop() { if (Serial.available() > 0) { String command = Serial.readStringUntil('\n'); handleSerialCommand(command); } updateLEDs(); } void handleSerialCommand(String command) { if (command.startsWith("BPM")) { bpm = command.substring(3).toInt(); Serial.print("BPM set to: "); Serial.println(bpm); } else if (command.startsWith("PLAY")) { lastBeat = millis(); } else if (command.startsWith("STOP")) { clearLEDs(); } else if (command.startsWith("COLOR")) { // Cambiar esquema de colores } } void updateLEDs() { unsigned long beatInterval = 60000 / bpm; unsigned long currentTime = millis(); if (currentTime - lastBeat < beatInterval) { float progress = (float)(currentTime - lastBeat) / beatInterval; switch(currentPattern) { case 0: chasePattern(progress); break; case 1: wavePattern(progress); break; case 2: pulsePattern(progress); break; } } FastLED.show(); } void chasePattern(float progress) { int activeLED = (int)(progress * NUM_LEDS); clearLEDs(); leds[activeLED] = CRGB::Red; leds[(activeLED + 1) % NUM_LEDS] = CRGB::Orange; }

🌐 Código JavaScript (WebMIDI)

// Solicitar acceso a MIDI if (navigator.requestMIDIAccess) { navigator.requestMIDIAccess() .then(onMIDISuccess, onMIDIFailure); } function onMIDISuccess(midiAccess) { console.log("MIDI Access Granted"); // Escuchar mensajes MIDI for (let input of midiAccess.inputs.values()) { input.onmidimessage = handleMIDIMessage; } } function handleMIDIMessage(message) { const [command, note, velocity] = message.data; // Clock MIDI (0xF8) if (command === 0xF8) { handleMIDIClock(); } // Start (0xFA) else if (command === 0xFA) { handleMIDIStart(); } // Stop (0xFC) else if (command === 0xFC) { handleMIDIStop(); } } let clockCount = 0; let bpm = 120; function handleMIDIClock() { clockCount++; // 24 clocks = 1 beat if (clockCount >= 24) { clockCount = 0; triggerLEDBeat(); } } function triggerLEDBeat() { // Enviar comando al Arduino if (serialPort && serialPort.writable) { const writer = serialPort.writable.getWriter(); writer.write(new TextEncoder().encode("BEAT\n")); writer.releaseLock(); } }

🔧 Instrucciones de Conexión

  1. Conecta los LEDs:
    • Data pin → Arduino pin 6 con resistencia 470Ω
    • 5V → Fuente de poder externa
    • GND → GND común
    • Añade capacitor 1000µF entre 5V y GND
  2. Configura el Arduino:
    • Sube el código Arduino usando IDE
    • Verifica la velocidad del serial (115200 baud)
    • Prueba con el monitor serial
  3. Conexión WebMIDI:
    • Abre en Chrome o Edge
    • Conecta tu controlador MIDI
    • Autoriza el acceso MIDI cuando se solicite
    • Configura tu DAW para enviar clock MIDI
← Volver a Tutoriales