#include "FastLED.h" #define NUM_STRIPS 2 #define NUM_LEDS_PER_STRIP 180 #define NUM_LEDS_PER_SQUARE 12 #define NUM_SQUARES_PER_STRIP 15 #define PIN_0 12 #define PIN_1 13 CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP]; void setup() { FastLED.addLeds(leds[0], NUM_LEDS_PER_STRIP); FastLED.addLeds(leds[1], NUM_LEDS_PER_STRIP); Serial.begin(9600); } int hex; int rgb; int led; int stored[3]; void loop() { if (Serial.available() > 0) { int data; switch (data = Serial.read()) { case 'n': nextColour(); break; case 'l': // end of LED nextLed(); break; case 'q': complete(); break; case 'r': resetState(); break; default: hex = (hex << 1) + charMap(data); break; } } } void nextColour() { stored[rgb++] = hex; hex = 0; } void nextLed() { CRGB color = CRGB(stored[0], stored[1], stored[2]); int strip = led / NUM_SQUARES_PER_STRIP; int start = (led * NUM_LEDS_PER_SQUARE) - (strip * NUM_LEDS_PER_STRIP); for (int i = start; i < start + NUM_LEDS_PER_SQUARE; i++) { leds[strip][i] = color; } led++; rgb = hex = 0; } void complete() { FastLED.show(); led = rgb = hex = 0; } void resetState() { led = rgb = hex = 0; } int charMap(char that) { switch (that) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'a': return 10; case 'b': return 11; case 'c': return 12; case 'd': return 13; case 'e': return 14; case 'f': return 15; } return -1; }