Close

Prototype Assembly: Part 3

A project log for Awesome Mix Vol. 1

Cassette Tape SAO with backlit LED spools and I2C-triggered visualizations animating Fast Forward, Rewind, Play, and Pause.

dustin-johnsonDustin Johnson 10/16/2024 at 04:150 Comments

Now I just need to code the demo:

// neopixel code
// --------------
#include <FastLED.h>

// neopixel code
// --------------
#define LED_PIN 5
#define LED_COUNT 14
#define LED_BRIGHTNESS 5
#define LED_CENTER_LEFT 0
#define LED_CENTER_RIGHT 7

// neopixel code
// --------------
// must be lowercase and this variable name or the compilation fails
CRGB leds[LED_COUNT];

// di0_demo1 code
// --------------
// exclude center LED
int LED_LEFT_MIN = 1;
int LED_LEFT_MAX = 6;
// exclude center LED
int LED_RIGHT_MIN = 8;
int LED_RIGHT_MAX = 13;
// keep the indexes for which LEDs are off (CRGB::Black)
int LED_LEFT_OFF_INDEX = LED_LEFT_MIN;
int LED_RIGHT_OFF_INDEX = LED_RIGHT_MIN;

// main setup
// --------------
void setup() {
  Serial.begin(9600);
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT);
  FastLED.setBrightness(LED_BRIGHTNESS);
  di0_demo1_setup();
}

// main loop
// --------------
void loop() {
  //di0_demo0();
  di0_demo1_loop();
}

// di0_demo1 code
// --------------
void di0_demo1_setup() {

  // illuminate left spool
  for (int i = LED_LEFT_MIN; i <= LED_LEFT_MAX; i++) {
    if (i == LED_CENTER_LEFT) { continue; }
    leds[i] = CRGB::WhiteSmoke;
    FastLED.show();
    delay(50);
  }

  // illuminate right spool
  for (int i = LED_RIGHT_MIN; i <= LED_RIGHT_MAX; i++) {
    if (i == LED_CENTER_RIGHT) { continue; }
    leds[i] = CRGB::WhiteSmoke;
    FastLED.show();
    delay(50);
  }
}

// di0_demo1 code
// --------------
void di0_demo1_loop() {

  // animation: PLAY (left spool)
  if (LED_LEFT_OFF_INDEX < LED_LEFT_MAX) {
    leds[LED_LEFT_OFF_INDEX] = CRGB::Blue;
    leds[LED_LEFT_OFF_INDEX+1] = CRGB::WhiteSmoke;
    LED_LEFT_OFF_INDEX++;    
  } else {
    leds[LED_LEFT_MAX] = CRGB::Blue;
    leds[LED_LEFT_MIN] = CRGB::WhiteSmoke;
    LED_LEFT_OFF_INDEX = LED_LEFT_MIN;
  }

  // animation: PLAY (right spool)
  if (LED_RIGHT_OFF_INDEX < LED_RIGHT_MAX) {
    leds[LED_RIGHT_OFF_INDEX] = CRGB::Blue;
    leds[LED_RIGHT_OFF_INDEX+1] = CRGB::WhiteSmoke;
    LED_RIGHT_OFF_INDEX++;    
  } else {
    leds[LED_RIGHT_MAX] = CRGB::Blue;
    leds[LED_RIGHT_MIN] = CRGB::WhiteSmoke;
    LED_RIGHT_OFF_INDEX = LED_RIGHT_MIN;
  }
  FastLED.show();  
  delay(100);
}

... and voila:

Discussions