// You must download and install the library from http://fastled.io/
#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define NUM_STRIPS 44 // Changed from original for 3 strings
#define NUM_LEDS_PER_STRIP 22 // Using 63 pixels per string
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS // Total number of LEDs
#define PIN 8
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
Adafruit_NeoMatrix matrix1 = Adafruit_NeoMatrix(NUM_STRIPS, NUM_LEDS_PER_STRIP, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix1.Color(255, 0, 0), matrix1.Color(0, 255, 0), matrix1.Color(255, 255, 0), matrix1.Color(0, 0, 255), matrix1.Color(255, 0, 255), matrix1.Color(0, 255, 255), matrix1.Color(255, 255, 255)
};
void setup() {
// Define the speed of the serial port
Serial.begin(115200);
matrix1.begin();
matrix1.setTextWrap(false);
}
void loop() {
// Set some counter / temporary storage variables
int cnt;
unsigned int num_leds;
unsigned int d1, d2, d3;
// Begin an endless loop to receive and process serial data
for (;;) {
// Set a counter to 0. This couter keeps track of the pixel colors received.
cnt = 0;
//Begin waiting for the header to be received on the serial bus
//1st character
while (!Serial.available());
if (Serial.read() != '>') {
continue;
}
//second character
while (!Serial.available());
if (Serial.read() != '>') {
continue;
}
//get the first digit from the serial bus for the number of pixels to be used
while (!Serial.available());
d1 = Serial.read();
//get the second digit from the serial bus for the number of pixels to be used
while (!Serial.available());
d2 = Serial.read();
//get the third digit from the serial bus for the number of pixels to be used
while (!Serial.available());
d3 = Serial.read();
//get the end of the header
while (!Serial.available());
if (Serial.read() != '<') {
continue;
}
while (!Serial.available());
if (Serial.read() != '<') {
continue;
}
// calculate the number of pixels based on the characters provided in the header digits
num_leds = (d1 - '0') * 100 + (d2 - '0') * 10 + (d3 - '0');
// ensure the number of pixels does not exceed the number allowed
if (num_leds > NUM_LEDS) {
continue;
}
/* ----have commeted this section to try and use matrix only----
// CODE ADDED - tell FastLED there's 63 PIXEL leds on pin 8, starting at index 0 in the led array
//this line change for one long string
FastLED.addLeds<WS2811, 8, RGB>(leds, 0, NUM_LEDS_PER_STRIP);
// CODE ADDED - tell FastLED there's 63 PIXEL leds on pin 9, starting at index 64 in the led array
FastLED.addLeds<WS2811, 9, RGB>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
// CODE ADDED - tell FastLED there's 63 PIXEL leds on pin 10, starting at index 127 in the led array
FastLED.addLeds<WS2811, 10, RGB>(leds, NUM_LEDS_PER_STRIP * 2, NUM_LEDS_PER_STRIP);
// CODE ADDED - tell FastLED there's 63 PIXEL leds on pin 11, starting at index 190 in the led array
FastLED.addLeds<WS2811, 11, RGB>(leds, NUM_LEDS_PER_STRIP * 3, NUM_LEDS_PER_STRIP);
// FastLED.addLeds<WS2811, 8,RGB>(leds, 0, 256);
*/
do {
while (!Serial.available());
leds[cnt].r = Serial.read();
while (!Serial.available());
leds[cnt].g = Serial.read();
while (!Serial.available());
leds[cnt++].b = Serial.read();
}
while (--num_leds); // Tell the FastLED Library it is time to update the strip of pixels
// FastLED.show(); // WOO HOO... We are all done and are ready to start over again!
matrix.show(); //hopefully will display
}
}