129 lines
2.1 KiB
C++
129 lines
2.1 KiB
C++
#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<NEOPIXEL, PIN_0>(leds[0], NUM_LEDS_PER_STRIP);
|
|
FastLED.addLeds<NEOPIXEL, PIN_1>(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 '0':
|
|
case '1':
|
|
case '2':
|
|
case '3':
|
|
case '4':
|
|
case '5':
|
|
case '6':
|
|
case '7':
|
|
case '8':
|
|
case '9':
|
|
case 'a':
|
|
case 'b':
|
|
case 'c':
|
|
case 'd':
|
|
case 'e':
|
|
case 'f':
|
|
hex = (hex << 2) + charMap(data);
|
|
break;
|
|
case 'n':
|
|
nextColour();
|
|
break;
|
|
case 'l': // end of LED
|
|
nextLed();
|
|
break;
|
|
case 'q':
|
|
complete();
|
|
break;
|
|
case 'r':
|
|
resetState();
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|