Skip to content

Instantly share code, notes, and snippets.

@frankkienl
Created February 4, 2022 14:33
Show Gist options
  • Save frankkienl/c0be0dc78fa90dd4ef0cb2a03787ccea to your computer and use it in GitHub Desktop.
Save frankkienl/c0be0dc78fa90dd4ef0cb2a03787ccea to your computer and use it in GitHub Desktop.
Arduino rgb matrix via serial
// Base64 - Version: Latest
#include <Base64.h>
//#include <base64.hpp>
// FastLED - Version: Latest
#include <FastLED.h>
#define LED_PIN 2
#define MATRIX_WIDTH 8
#define MATRIX_HEIGHT 8
// #define NUM_LEDS 64
#define NUM_LEDS 128
#define BRIGHTNESS 12
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
char rainbow2[] = "AAAAAAAA/wAA/wAA/wAA/wAAAAAAAAAAAAAA/wAA/4wA/4wA/4wA/4wA/wAAAAAA/wAA/4wA/+wA/+wA/+wA/+wA/4wA/wAA/4wA/+wAAP8gAP8gAP8gAP8g/+wA/4wA/+wAAP8gAM//AM//AM//AM//AP8g/+wAAP8gAM//uwD/uwD/uwD/uwD/AM//AP8gAM//uwD/AAAAAAAAAAAAAAAAuwD/AM//uwD/AAAAAAAAAAAAAAAAAAAAAAAAuwD/AAAAAAAA/wAA/wAA/wAA/wAAAAAAAAAAAAAA/wAA/4wA/4wA/4wA/4wA/wAAAAAA/wAA/4wA/+wA/+wA/+wA/+wA/4wA/wAA/4wA/+wAAP8gAP8gAP8gAP8g/+wA/4wA/+wAAP8gAM//AM//AM//AM//AP8g/+wAAP8gAM//uwD/uwD/uwD/uwD/AM//AP8gAM//uwD/AAAAAAAAAAAAAAAAuwD/AM//uwD/AAAAAAAAAAAAAAAAAAAAAAAAuwD/";
void setup() {
delay(3000);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
patternBase64(rainbow2);
FastLED.show();
Serial.begin(38400);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("rgb matrix via serial by FrankkieNL");
}
void loop() {
//Read a whole strip's worth of RGB data directly into the leds array at once
//https://github.com/FastLED/FastLED/wiki/Controlling-leds#read-rgb-data-from-serial
//Serial.readBytes( (char*)leds, NUM_LEDS * 3);
if (Serial.available()){
Serial.readBytes( (char*)leds, NUM_LEDS * 3);
FastLED.show();
}
}
void patternBase64(char inputString[]) {
int decodedLength = Base64.decodedLength(inputString, strlen(inputString));
char decodedString[decodedLength];
Base64.decode(decodedString, inputString, strlen(inputString));
for (int i = 0; i < decodedLength; i+=3) {
leds[i/3] = CRGB(decodedString[i],decodedString[i+1],decodedString[i+2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment