#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 11
#define DATA_PIN_R 13
//#define CLK_PIN 4
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 85
CRGB leds[NUM_LEDS];
CRGB leds_display[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
int height = 5;
int width = 15;
int baner_width = 70;
int animationPos = 0;
// Params for width and height
const uint8_t kMatrixWidth = 15;
const uint8_t kMatrixHeight = 5;
// Param for different pixel layouts
const bool kMatrixSerpentineLayout = false; // true
const bool kMatrixVertical = false;
const uint8_t kMatrixLeftMargin = 1;
const uint8_t kMatrixRightMargin = 2;
#define NUM_LEDS_M ((kMatrixLeftMargin+kMatrixWidth+kMatrixRightMargin) * kMatrixHeight)
CRGB ledsM[ NUM_LEDS_M + 1];
// 'skel', 70x5px
const unsigned char epd_bitmap_skel [] PROGMEM = {
0x1f, 0x1f, 0x08, 0x0a, 0x0a, 0x0a, 0x02, 0x1f, 0x00, 0x1b, 0x15, 0x0e, 0x1f, 0x00, 0x0a, 0x0a,
0x0a, 0x0e, 0x1f, 0x1f, 0x00, 0x0f, 0x0f, 0x0f, 0x1f, 0x00, 0x0f, 0x0f, 0x0f, 0x1f, 0x0e, 0x0e,
0x00, 0x0e, 0x0e, 0x1f, 0x00, 0x0e, 0x0a, 0x0a, 0x02, 0x1f, 0x00, 0x0a, 0x0a, 0x0a, 0x0e, 0x1f,
0x1f, 0x1f, 0x1f, 0x13, 0x05, 0x07, 0x0f, 0x0f, 0x08, 0x08, 0x00, 0x08, 0x08, 0x0f, 0x0f, 0x07,
0x05, 0x13, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 96)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_skel
};
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(ledsM, NUM_LEDS_M).setCorrection(TypicalSMD5050);
//FastLED.addLeds<LED_TYPE,DATA_PIN_R,COLOR_ORDER>(ledsR, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness(BRIGHTNESS);
for (int a = 0; a < NUM_LEDS; a++) {
//leds[a] = CHSV(a*4,255,255);
ledsM[a] = CRGB::Green;
}
FastLED.show();
}
void loop() {
int cc = 0;
int pixel = 0;
int pixel2 = 0;
if (1 == 1) {
for (int x = 0; x < width; x++) {
int bpos = animationPos+x;
if (bpos > baner_width) {
bpos = bpos - baner_width;
}
int combinedColor = pgm_read_byte_near(epd_bitmap_skel + (bpos));
for (int y = 0; y < height;y++) {
cc = ((4-y)*width + x);
if (bitRead(combinedColor,(4-y)) == 0) {
//leds[cc] = CRGB::Yellow;
ledsM[myXY(x,y)] = CRGB::Yellow;
}
else {
//leds[cc] = CRGB::CRGB::BlueViolet;
ledsM[myXY(x,y)] = CRGB::BlueViolet;
}
}
}
}
// calculate_leds_show();
FastLED.show();
animationPos++;
if (animationPos > baner_width) {
animationPos = 0;
}
delay(100);
}
void calculate_leds_show() {
int offset = 1;
for (int x = 0;x < width;x++) {
leds_display[(x+offset)] = leds[x];
}
offset = 17; // 5
for (int x = 15;x < 30;x++) {
leds_display[((30-x)+offset)] = leds[x];
}
offset = 5;
for (int x = 30;x < 45;x++) {
leds_display[(x+offset)] = leds[x];
}
offset = 51;
for (int x = 45;x < 60;x++) {
leds_display[((60-x)+offset)] = leds[x];
}
offset = 9;
for (int x = 60;x < 75;x++) {
leds_display[(x+offset)] = leds[x];
}
}
// Set 'kMatrixSerpentineLayout' to false if your pixels are
// laid out all running the same way, like this:
//
// 0 > 1 > 2 > 3 > 4
// |
// .----<----<----<----'
// |
// 5 > 6 > 7 > 8 > 9
// |
// .----<----<----<----'
// |
// 10 > 11 > 12 > 13 > 14
// |
// .----<----<----<----'
// |
// 15 > 16 > 17 > 18 > 19
//
// Set 'kMatrixSerpentineLayout' to true if your pixels are
// laid out back-and-forth, like this:
//
// 0 > 1 > 2 > 3 > 4
// |
// |
// 9 < 8 < 7 < 6 < 5
// |
// |
// 10 > 11 > 12 > 13 > 14
// |
// |
// 19 < 18 < 17 < 16 < 15
//
// Bonus vocabulary word: anything that goes one way
// in one row, and then backwards in the next row, and so on
// is call "boustrophedon", meaning "as the ox plows."
// This function will return the right 'led index number' for
// a given set of X and Y coordinates on your matrix.
// IT DOES NOT CHECK THE COORDINATE BOUNDARIES.
// That's up to you. Don't pass it bogus values.
//
// Use the "XY" function like this:
//
// for( uint8_t x = 0; x < kMatrixWidth; x++) {
// for( uint8_t y = 0; y < kMatrixHeight; y++) {
//
// // Here's the x, y to 'led index' in action:
// leds[ XY( x, y) ] = CHSV( random8(), 255, 255);
//
// }
// }
//
//
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;
}
uint16_t myXY( uint8_t x, uint8_t y)
{
uint16_t i;
if( x >= kMatrixWidth) return -1;
if( y >= kMatrixHeight) return -1;
if( kMatrixSerpentineLayout == false) {
if (kMatrixVertical == false) {
i = (y * (kMatrixLeftMargin+kMatrixWidth+kMatrixRightMargin))+ kMatrixLeftMargin + x;
} else {
//todo poprawic o marginesy
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;
i = (y * (kMatrixLeftMargin+kMatrixWidth+kMatrixRightMargin)) + kMatrixLeftMargin + reverseX;
} else {
// Even rows run forwards
//i = (y * kMatrixWidth) + x;
i = (y * (kMatrixLeftMargin+kMatrixWidth+kMatrixRightMargin)) + kMatrixLeftMargin + x;
}
}
else { // vertical positioning
if ( x & 0x01) {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
} else {
i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
}
}
}
if (NUM_LEDS_M < i) {
return -1;
}
return i;
}