Skip to content

Instantly share code, notes, and snippets.

@frankkienl
Created July 4, 2021 18:41
Show Gist options
  • Save frankkienl/d36577f0e372a2b300a127166209170c to your computer and use it in GitHub Desktop.
Save frankkienl/d36577f0e372a2b300a127166209170c to your computer and use it in GitHub Desktop.
Arduino 8x8 led matrix
// 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 BRIGHTNESS 12
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
//base64
char pika[] = "AAAAgICAgICAAAAAAAAAAAAAAAAAgICA/4gZAAAAAAAAAAAA/2oA/9gAAAAAAAAAAAAAAAAAAAAA/9gA/9gA/9gA/9gA/4gZAAAA/9gA/9gAAAAA/9gAAAAA/2oA/2oA/2oA/2oAAAAA/wAA/9gA/9gA/9gA/4gZAAAA/4gZ/4gZ/4gZ/9gAAAAA/4gZAAAAAAAA/4gZ/9gA/3kF/9gA/4gZAAAAAAAAAAAA/3kF/2oA/2oA/3kF/9gAAAAAAAAA";
char klaver4_geel[] = "AAAA/+MA/+MAAAAAAAAA/+MA/+MAAAAA/+MA/+MA/+MAAAAAAAAA/+MA/+MA/+MA/+MA/+MA/+MAAAAAAAAA/+MA/+MA/+MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MA/+MA/+MAAAAAAAAA/+MA/+MA/+MA/+MA/+MA/+MAAAAAAAAA/+MA/+MA/+MAAAAA/+MA/+MAAAAAAAAA/+MA/+MAAAAA";
//char rainbow1[] = "AAAAAAAAAAAA/wAA/wAAAAAAAAAAAAAA/wAA/wAA/wAA/4wA/4wA/wAA/wAA/wAA/4wA/4wA/4wA/+wA/+wA/4wA/4wA/4wA/+wA/+wA/+wAAP8gAP8g/+wA/+wA/+wAAP8gAP8gAP8gAM//AM//AP8gAP8gAP8gAM//AM//AM//uwD/uwD/AM//AM//AM//uwD/uwD/uwD/AAAAAAAAuwD/uwD/uwD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
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/";
char rd[] = "AAAAAAAAAAAA////////AAAAAAAAAAAAAAAAAAAA////////////////////AAAA////////////////////////////AAAAAAAAAAAA////////////////////AAAAAAAAAAAA/wAA/9gAACb/AAAAAAAAAAAAAAAAAAAAACb//9gA/wAAAAAAAAAAAAAAAAAAAAAAAAAA/wAA/9gAACb/AAAAAAAAAAAAAAAA/9gA/wAAAAAAAAAAAAAAAAAA";
// char plus[] = "AAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/ABf/AAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAA";
// char kruis[] = "ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/AAAAABf/AAAAAAAAAAAAAAAAABf/AAAAAAAAAAAAABf/AAAAAAAAABf/AAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAAAAAABf/ABf/AAAAAAAAAAAAAAAAAAAAABf/AAAAAAAAABf/AAAAAAAAAAAA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AAAAAAAA/wAA/zkA/zkA/wAAAAAAAAAAAAAAAAAAAAAA/wAA/wAAAAAAAAAAAAAA";
// char heart4[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/zkA/zkAAAAAAAAA/zkA/zkAAAAAAAAA/zkA/zkA/zkA/zkA/zkA/zkAAAAAAAAA/zkA/zkA/zkA/zkA/zkA/zkAAAAAAAAA/zkA/zkA/zkA/zkA/zkA/zkAAAAAAAAAAAAA/zkA/zkA/zkA/zkAAAAAAAAAAAAAAAAAAAAA/zkA/zkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
char pokebal[] = "AAAAAAAA/wAA/wAA/wAA/wAAAAAAAAAAAAAA/wAA/wAA/wAA/wAA/wAA/wAAAAAA/wAA/wAA/wAA/wAA/wAA/wAA/wAA/wAA/wAA/wAAAAAAAAAAAAAAAAAA/wAA/wAAAAAAAAAAAAAA////////AAAAAAAAAAAA////////AAAAAAAAAAAAAAAA////////AAAA////////////////////////AAAAAAAAAAAA////////////////AAAAAAAA";
char dick[] = "EgsGExEQ////AAAA////AAAAAAAAAAAAAAAA////AAAA/6aO/6aOExMTCQkJBAMCAAAA/////8CO/8CO/8CO/8COAAAAAAAA////AAAA/8CO/8CO/8CO/8COAAAA////AAAAAAAA/8CO/8CO/8CO/8COAAAA////AAAA/6aO/6aO/8CO/8CO/6aO/6aO/////6aOAAAAAAAA/6aO/6aOAAAAAAAA/6aOAAAA/6aO/6aOAAAAAAAA/6aO/6aOAAAA";
void setup() {
delay(3000);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
patternTester();
//indexTester();
//xyTester();
//allesAanTester();
patternsBase64Tester();
}
void patternsBase64Tester() {
// patternBase64(pika);
// FastLED.show();
// delay(750);
patternBase64(dick);
FastLED.show();
delay(1750);
patternBase64(klaver4_geel);
FastLED.show();
delay(750);
// patternBase64(rainbow1);
// FastLED.show();
// delay(750);
patternBase64(rainbow2);
FastLED.show();
delay(750);
patternBase64(rd);
FastLED.show();
delay(750);
// patternBase64(plus);
// FastLED.show();
// delay(750);
// patternBase64(kruis);
// FastLED.show();
// delay(750);
// patternBase64(no_entry);
// FastLED.show();
// delay(750);
// patternBase64(heart);
// FastLED.show();
// delay(750);
// patternBase64(heart2);
// FastLED.show();
// delay(750);
// patternBase64(heart3);
// FastLED.show();
// delay(750);
// patternBase64(heart4);
// FastLED.show();
// delay(750);
patternBase64(pokebal);
FastLED.show();
delay(750);
//all off
for (int i = 0; i<NUM_LEDS;i++){
leds[i] = CRGB::Black;
}
FastLED.show();
delay(250);
}
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]);
}
}
void patternTester() {
//Assuming square matrix
//cross
for (int i = 0; i < MATRIX_WIDTH/2; i++) {
//topleft
leds[XY(i,i)] = CRGB::Red;
//topright
leds[XY(MATRIX_WIDTH-1-i,i)] = CRGB::Red;
//bottomleft
leds[XY(i,MATRIX_WIDTH-1-i)] = CRGB::Red;
//bottomright
leds[XY(MATRIX_WIDTH-1-i,MATRIX_WIDTH-1-i)] = CRGB::Red;
}
FastLED.show();
delay(750);
//all off
for (int i = 0; i<NUM_LEDS;i++){
leds[i] = CRGB::Black;
}
FastLED.show();
delay(250);
//rounded square
for (int i = 0; i<MATRIX_WIDTH/2; i++){
//top
leds[XY(2+i,0)] = CRGB::Green;
//bottom
leds[XY(2+i,MATRIX_WIDTH-1)] = CRGB::Green;
//left
leds[XY(0,2+i)] = CRGB::Green;
//right
leds[XY(MATRIX_WIDTH-1,2+i)] = CRGB::Green;
}
//corners
leds[XY(1,1)] = CRGB::Green; //topleft
leds[XY(MATRIX_WIDTH-2,1)] = CRGB::Green; //topright
leds[XY(1,MATRIX_WIDTH-2)] = CRGB::Green; //bottomleft
leds[XY(MATRIX_WIDTH-2,MATRIX_WIDTH-2)] = CRGB::Green; //bottomright
FastLED.show();
delay(750);
//all off
for (int i = 0; i<NUM_LEDS;i++){
leds[i] = CRGB::Black;
}
FastLED.show();
delay(250);
}
void allesAanTester() {
for (int i = 0; i<NUM_LEDS;i++){
leds[i] = CRGB::Blue;
}
FastLED.show();
delay(500);
for (int i = 0; i<NUM_LEDS;i++){
leds[i] = CRGB::Black;
}
FastLED.show();
delay(250);
}
void indexTester() {
int index = 0;
while (index < NUM_LEDS){
// Turn the first led red for 1 second
leds[index] = CRGB::Purple;
FastLED.show();
delay(100);
// Set the first led back to black for 1 second
leds[index] = CRGB::Black;
FastLED.show();
delay(1);
index++;
}
}
void xyTester() {
for (int yy = 0; yy<MATRIX_HEIGHT; yy++) {
for (int xx = 0; xx<MATRIX_WIDTH; xx++) {
int i = XY(xx,yy);
leds[i] = CRGB::Yellow;
FastLED.show();
delay(100);
leds[i] = CRGB::Black;
FastLED.show();
delay(1);
}
}
}
int XY(int x, int y) {
int i;
if( y & 0x01) {
// Odd rows run backwards
int reverseX = (MATRIX_WIDTH - 1) - x;
i = (y * MATRIX_WIDTH) + reverseX;
} else {
// Even rows run forwards
i = (y * MATRIX_WIDTH) + x;
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment