#include <Arduino.h>
#include <FastLED.h>
#define LED_PIN 7
// Params for LED width and height
const uint8_t kMatrixWidth = 10;
const uint8_t kMatrixHeight = 10;
uint8_t v_offset = 0 ;
uint8_t bufWidth = 56 ;
uint8_t bufHeight = 10 ;
// uint8_t v_offset;
CRGB leds[kMatrixWidth * kMatrixHeight] ;
// Param for different pixel layouts
bool kMatrixSerpentineLayout = true;
bool kMatrixVertical = false;
int8_t buf1[]= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,
1,1,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,
1,1,0,0,1,1,0,0,0,1,1,0,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,
1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,
1,1,0,0,1,1,0,0,0,1,1,0,1,0,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,1,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,
1,1,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,
1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
} ;
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
if (kMatrixVertical == false) {
i = (y * kMatrixWidth) + x;
} else {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
}
}
if( kMatrixSerpentineLayout == true) {
if (kMatrixVertical == false) {
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;
}
} else { // vertical positioning
if ( x & 0x01) {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
} else {
i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
}
}
}
return i;
}
void shift(int8_t buf[], int8_t szx, int8_t szy)
{
int8_t tmp[szy];
int i,j,indx;
/* copy first column to tmp */
for(j=0;j<szy;j++) {
indx=j*szx;
tmp[j]=buf1[indx] ;
}
/* shift columns */
for(i=0;i<szx-1;i++)
for(j=0;j<szy;j++) {
indx=(j * szx) + i;
buf1[indx]=buf1[indx+1] ;
}
/* move first column to last */
for(j=0;j<szy;j++) {
indx=(j * szx) + szx-1;
buf1[indx]=tmp[j] ;
}
}
void writeled(int8_t buf[]) {
int indx, indx1 ;
for(int i = 0 ; i<kMatrixWidth ; i++) {
for(int j = 0 ; j<kMatrixHeight; j++)
{
indx1=(j * bufWidth) + i;
indx=XY(i,j) ;
leds[indx]= ( buf1[indx1] == 1 ) ? CRGB(75, 56, 113) : CRGB::Black ;
}
}
}
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2811, LED_PIN, GRB>(leds, kMatrixWidth*kMatrixHeight);
FastLED.clear();
// FastLED.show() ;
}
void loop() {
// put your main code here, to run repeatedly:
for(v_offset=0; v_offset<2 ; v_offset++) {
for(int i = 0 ; i < bufWidth; i++) {
writeled(buf1) ;
FastLED.show();
delay(50) ;
shift(buf1,bufWidth,bufHeight);
}
}
}