ITP blog ยท physical-computing

Week 13 - Dance floor MPC progress, part 3

5 December 2018

The project has a new formalized name, Dance Floor MPC.

Hardware design

I sketched out my latest ideas for the hardware design using what I've learned so far:

dance-floor-9

LEDs

I plugged in my LEDs for the first time today and managed to get them synced up to the Tone.js transport using serial communication:

I'm using the FastLED library here. On the Arduino side, the code to get this working looks like this:

#define TRANSPORT_STEP_DATA_PREFIX "transportStep:"

String data = Serial.readStringUntil('\n');

void loop() {
    if (Serial.available() > 0) {
        if (data.startsWith(TRANSPORT_STEP_DATA_PREFIX)) {
            // "transportStep:32"
            char* stepString = &data[strlen(TRANSPORT_STEP_DATA_PREFIX)];
            currentTimelineStep = atoi(stepString);
            clearTimelineLeds();
            lightTimelineStepLeds(currentTimelineStep);
        }
    }

    // other stuff
}

void clearTimelineLeds() {
    for (int i = 0; i < TIMELINE_NUM_LEDS; i++) {
        timelineLeds[i] = CRGB::Black;
    }
}

void lightTimelineStepLeds(int i) {
    timelineLeds[currentTimelineStep] = CRGB::Gray;
    timelineLeds[currentTimelineStep + 1] = CRGB::Gray;
    timelineLeds[currentTimelineStep + (TIMELINE_NUM_LEDS / 2)] = CRGB::Gray;
    timelineLeds[currentTimelineStep + (TIMELINE_NUM_LEDS / 2) + 1] = CRGB::Gray;
    FastLED.show();
}