#include "FastLED.h"
// Matrix size
#define HEIGHT 16
#define WIDTH 16
#define NUM_LEDS WIDTH * HEIGHT
#define MATRIX_TYPE 1
#define DATA_PIN 3 // LEDs pin
#define BRIGHTNESS 255 // LED brightness
CRGB leds[NUM_LEDS]; // Define the array of leds
// ******************************************************************************
//horisontal move heart bump
//for 14x14 Soulmate matrix ( and any other now )
//Yaroslaw Turbin 29.12.2020
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//upd 12-03-2020 fix for any resolution and added move texture
CRGB chsvLut[256];
int8_t bump[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0b, 0x12, 0x18, 0x13, 0x09, 0x0a, 0x15, 0x18, 0x12, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0b, 0x1e, 0x26, 0x2c, 0x30, 0x2f, 0x30, 0x30, 0x2c, 0x26, 0x1b, 0x0b, 0x00, 0x00,
0x00, 0x00, 0x17, 0x26, 0x32, 0x39, 0x3e, 0x41, 0x42, 0x3e, 0x39, 0x31, 0x26, 0x15, 0x00, 0x00,
0x00, 0x03, 0x1c, 0x2d, 0x39, 0x3f, 0x43, 0x47, 0x47, 0x44, 0x3f, 0x37, 0x2d, 0x1a, 0x02, 0x00,
0x00, 0x00, 0x18, 0x2e, 0x38, 0x41, 0x47, 0x46, 0x46, 0x45, 0x40, 0x38, 0x2c, 0x16, 0x00, 0x00,
0x00, 0x00, 0x09, 0x26, 0x36, 0x3e, 0x43, 0x46, 0x46, 0x42, 0x3f, 0x35, 0x25, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0b, 0x28, 0x38, 0x3e, 0x41, 0x42, 0x3f, 0x37, 0x28, 0x09, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0d, 0x2c, 0x38, 0x3c, 0x3c, 0x37, 0x2a, 0x0b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x2d, 0x34, 0x34, 0x2c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x11, 0x2b, 0x29, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void generateCHSVlut(){
for (int j= 0; j<256; j++)
// chsvLut[j]=CHSV(130,255,j); // for one color
chsvLut[j]=HeatColor(j/1.7);
}
void Bumpmap(int8_t lightx, int8_t lighty){
int col;
// byte text_y_offs = beatsin8(5,1,32); // for X and Y texture move
// byte text_x_offs = beatsin8(6,1,32); // for X and Y texture move
byte text_y_offs = 14; // for horisontal texture move for 16x16 matrix byte text_y_offs = 13;
byte text_x_offs = beatsin8(10,1,32); // for horisontal texture move
// byte text_y_offs = beatsin8(5,1,32); // for vertical texture move
// byte text_x_offs = 0; // for vertical texture move
// byte text_y_offs = 0; //for stay
// byte text_x_offs = 0; //for stay
int8_t vly=lighty;
for (byte y = 0; y < WIDTH; y++) {
++vly;
text_y_offs=(text_y_offs+1)%15; if (text_y_offs == 0) {text_y_offs++;}
int8_t vlx=lightx;
int y_offs=text_y_offs*16;
int x_offs = text_x_offs;
for (byte x = 0; x < HEIGHT; x++) {
++vlx;
x_offs = (x_offs+1)&15; //%16 changed to &15, be carieful if texture size not 16x16!
int8_t nx=bump[x_offs+y_offs+1]-bump[x_offs+y_offs-1];
int8_t ny=bump[x_offs+y_offs+16]-bump[x_offs+y_offs-16];
byte difx=abs8(vlx*7-nx);
byte dify=abs8(vly*7-ny);
uint16_t temp = difx*difx+dify*dify;
// col = (255-(temp/32)); // its very fast
col = temp? 255-sqrt16(temp)*3 : 255; //3 is contrast value, try up if your matrix very blur
if (col<0) col=0;
leds[XY(x,y)] = chsvLut[col]; //thx satubarosu ))
}
}
}
// ******************************************************************************
uint16_t XY (uint8_t x, uint8_t y) {
return (y * WIDTH + x);
}
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
pinMode(2, INPUT_PULLUP);
}
void loop() {
#define BumpmapSpeed 20
static byte setUp = 1;
if (setUp) { generateCHSVlut(); setUp =0;}
int8_t lightX = 1- beatsin8(BumpmapSpeed,1,HEIGHT+1,64);
int8_t lightY = 1- beatsin8(BumpmapSpeed-10,1,WIDTH+1);
Bumpmap(lightX, lightY);
FastLED.show();
} //loop
FPS: 0
Power: 0.00W
Power: 0.00W