// source: https://editor.soulmatelights.com/gallery/843-squares-and-dots
#include "FastLED.h"
#define DATA_PIN 2
#define BRIGHTNESS 255
#define NUM_LEDS 256
#define LED_COLS 16
#define LED_ROWS 16
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
//#define FRAMES_PER_SECOND 60
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
const bool kMatrixSerpentineLayout = false;
const byte sprites[2][3][3] = {1,1,1,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,};
void printSpr(byte x, byte y, byte numSpr) {
byte hue = random8();
byte y1 = y;
for (int j = 0; j < 3; j++) {
byte x1 = x;
for (int i = 0; i < 3; i++) {
uint16_t index = XY(x1, y1);
if (sprites[numSpr][i][j]) leds[index].setHue(hue);
else leds[index] = 0;
x1++;
Serial.println(index); Serial.println("print");
}
y1++;
}
}
void initSCR() {
for (byte x = 0; x < LED_COLS / 3 + 1; x++) {
for (byte y = 0; y < LED_ROWS / 3 + 1; y++) {
printSpr(x * 3, y * 3, random8(2));
}
}
}
void setup() {
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS); //setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
}
void loop()
{
static byte init = 1;
//if (init == 1) {
//initSCR(); init = 0; }
EVERY_N_MILLISECONDS(300) {
printSpr((random8(LED_COLS) % (LED_COLS / 3 + 1)) * 3, (random8(LED_ROWS) % (LED_ROWS / 3 + 1)) * 3, random8(2));
//FastLED.show();
Serial.println("test");
}
FastLED.show();
//Serial.println("show!");
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}