#include <FastLED.h>
#include "LEDMatrix.h"
/*********************************************
/* Modifié pour K SIGN WILLERS LE 19-11-2021 */
/*********************************************/
#define LED_PIN 3 // Output pin for LEDs [6]
#define COLOR_ORDER GRB // Color order of LED string [RGB]
#define CHIPSET WS2811 // LED string type [WS2811]
#define BRIGHTNESS 200 // Overall brightness [50]
#define LAST_VISIBLE_LED 135 // Last LED that's visible [135]
#define MAX_MILLIAMPS 5000 // Max current in mA to draw from supply [500]
#define SAMPLE_WINDOW 100 // How many ms to sample audio for [100]
#define BTN_PIN 3 // Pin for button [3]
#define DEBOUNCE_MS 20 // Number of ms to debounce the button [20]
#define LONG_PRESS 500 // Number of ms to hold the button to count as long press [500]
#define PATTERN_TIME 10 // Seconds to show each pattern on autoChange [10]
#define kMatrixWidth 7 // Matrix width [15]
#define kMatrixHeight 13 // Matrix height [11]
#define NUM_LEDS 182 // Total number of Leds
#define NUM_LEDS_CONTOUR 50
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight) // Largest dimension of matrix
#define FRAMES_PER_SECOND 60 // Vous pouvez ajuster cette valeur en fonction de la vitesse souhaitée de l'effet
//CRGB leds[ NUM_LEDS + 1 ];
/*********************************************
/* MAPPING : Modifié pour K SIGN WILLERS LE 19-11-2021 */
/*********************************************/
// Helper to map XY coordinates to irregular matrix
uint16_t XY (uint8_t x, uint8_t y) { // Cette fonction retourne un numéro de LED sur base des coordonnées x et y qui lui sont transmises en argument (tenant compte du mapping effectué dans la table XYTable)
// any out of bounds address maps to the first hidden pixel
if ( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
return 183;
}
const uint8_t XYTable[] = {
1, 3, 5, 137, 138, 139, 140,
11, 9, 7, 144, 143, 142, 141,
13, 15, 17, 145, 146, 147, 148,
23, 21, 19, 153, 152, 151, 150,
25, 27, 29, 154, 93, 95, 97,
35, 33, 31, 155, 91, 101, 99,
37, 39, 77, 79, 89, 103, 105,
43, 41, 75, 81, 87, 107, 156,
45, 47, 73, 83, 85, 109, 111,
51, 49, 71, 157, 117, 115, 113,
53, 55, 69, 158, 119, 121, 123,
59, 57, 67, 159, 129, 127, 125,
61, 63, 65, 160, 131, 133, 135
};
uint8_t i = (y * kMatrixWidth) + x;
uint8_t j = XYTable[i];
return j;
}
CRGB leds_plus_safety_pixel[ NUM_LEDS + 1];
CRGB* const leds( leds_plus_safety_pixel + 1);
CRGB ledsCopy[NUM_LEDS];
int faderate = 100;
uint16_t XYsafe( uint8_t x, uint8_t y)
{
if( x >= kMatrixWidth) return -1;
if( y >= kMatrixHeight) return -1;
return XY(x,y);
}
/* Plasma **********************************************************************/
DEFINE_GRADIENT_PALETTE(PlasmaColors_p) {
0, 0, 0, 0, // Noir
32, 16, 0, 16, // Violet foncé
64, 255, 0, 255, // Magenta vif
96, 255, 64, 64, // Rouge vif
128, 255, 255, 0, // Jaune vif
160, 64, 255, 64, // Vert vif
192, 0, 255, 255, // Cyan vif
224, 0, 64, 255, // Bleu vif
255, 0, 0, 0 // Noir
};
void plasmaEffect() {
uint8_t plasmaSpeed = 2; // Vitesse de l'effet
uint8_t colorIndex = millis() >> 8; // Utilisation du temps pour changer la couleur
uint8_t offset = 0;
for (uint8_t y = 0; y < kMatrixHeight; y++) {
for (uint8_t x = 0; x < kMatrixWidth; x++) {
uint8_t c = sin8(sqrt(sq(x - (kMatrixWidth / 2)) + sq(y - (kMatrixHeight / 2)) + offset)); // Calcul du plasma
uint8_t color = sin8(c + colorIndex); // Changement de couleur en fonction du temps
uint16_t index = XY(x, y);
CRGBPalette16 palette = PlasmaColors_p;
CRGB colorOutput = ColorFromPalette(palette, color, 255, LINEARBLEND); // Appliquer la couleur à la LED
leds[index] = colorOutput;
}
}
offset += plasmaSpeed; // Changer l'offset pour l'animation
}
/* Fin déclarations pour Plasma ************************************************/
void setup() {
// put your setup code here, to run once:
//Serial.begin(9600);
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness( BRIGHTNESS );
//Serial.begin(115200);
FastLED.clear();
FastLED.show();
}
void AdjustDimmedDiags(int separation, int offset, int tempo, bool moveUpward, bool angleNegatif, int blurIntensity) {
unsigned long previousMillis = 0;
while (true) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= tempo) {
previousMillis = currentMillis;
fill_solid(leds, NUM_LEDS, CRGB::Black);
fill_solid(ledsCopy, NUM_LEDS, CRGB::Black);
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
int angleMultiplier = (angleNegatif ? 1 : -1);
if (((i * angleMultiplier - j) + offset) % (separation + 1) == 0) {
leds[XY(i, j)] = CRGB::Yellow;
}
}
}
for (int i = 0; i < NUM_LEDS; i++) {
int sumR = 0, sumG = 0, sumB = 0;
if (leds[i] != CRGB::Yellow) {
for (int dx = -blurIntensity; dx <= blurIntensity; dx++) {
for (int dy = -blurIntensity; dy <= blurIntensity; dy++) {
int x = (i % kMatrixWidth) + dx;
int y = (i / kMatrixWidth) + dy;
if (x >= 0 && x < kMatrixWidth && y >= 0 && y < kMatrixHeight) {
sumR += leds[XY(x, y)].r;
sumG += leds[XY(x, y)].g;
sumB += leds[XY(x, y)].b;
}
}
}
ledsCopy[i].r = sumR / ((blurIntensity + 1) * (2 * blurIntensity + 1));
ledsCopy[i].g = sumG / ((blurIntensity + 1) * (2 * blurIntensity + 1));
ledsCopy[i].b = sumB / ((blurIntensity + 1) * (2 * blurIntensity + 1));
} else {
ledsCopy[i] = leds[i];
}
}
memcpy(leds, ledsCopy, NUM_LEDS * sizeof(CRGB));
if (moveUpward) {
offset--;
if (offset < 0) {
offset = kMatrixHeight - 1;
}
} else {
offset++;
if (offset >= kMatrixHeight) {
offset = 0;
}
}
FastLED.show();
}
}
}
void loop() {
AdjustDimmedDiags(3, 0, 300, false, true, 4); // separation, offset, tempo, moveUpward, angleNegatif, blurIntensity
// moveUpward à true et angleNegatif à false = comportement par défaut de l'ancien effet Diagonals
}