// originally from:
// https://github.com/sutaburosu/scintillating_heatshrink/
#include <Arduino.h>
#include <FastLED.h>
enum XY_matrix_config { SERPENTINE = 1, ROWMAJOR = 2, FLIPMAJOR = 4, FLIPMINOR = 8 };
// MAX_MILLIWATTS can only be changed at compile-time. Use 0 to disable limit.
// Brightness can be changed at runtime via serial with 'b' and 'B'
#define BRIGHTNESS 255
#define LED_PIN 2
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define kMatrixWidth 7
#define kMatrixHeight 13
#define XY_MATRIX (ROWMAJOR)
#define NUM_LEDS ((kMatrixWidth) * (kMatrixHeight))
CRGB leds_plus_safety_pixel[NUM_LEDS + 1];
CRGB* const leds(leds_plus_safety_pixel + 1);
uint16_t XY(uint8_t x, uint8_t y) {
uint8_t major, minor, sz_major, sz_minor;
if (x >= kMatrixWidth || y >= kMatrixHeight)
return NUM_LEDS;
if (XY_MATRIX & ROWMAJOR)
major = x, minor = y, sz_major = kMatrixWidth, sz_minor = kMatrixHeight;
else
major = y, minor = x, sz_major = kMatrixHeight, sz_minor = kMatrixWidth;
if (XY_MATRIX & FLIPMINOR)
minor = sz_minor - 1 - minor;
if ((XY_MATRIX & FLIPMAJOR) ^ (minor & 1 && (XY_MATRIX & SERPENTINE)))
major = sz_major - 1 - major;
return (uint16_t) minor * sz_major + major;
}
DEFINE_GRADIENT_PALETTE(AtttidGrPal){
0, 255, 80, 1,
100, 255, 150, 0,
180, 255, 100, 0,
200, 255, 90, 0,
255, 255, 80, 0
};
CRGBPalette16 attmyPal = AtttidGrPal;
uint8_t colorIndex[NUM_LEDS];
int Current_Sinus_ATTTID;
int CurrentState;
unsigned long millis_fromset; // Use for waiting for the setting tempo
void setup() {
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
ATTTIDStartEffect();
}
void loop() {
Current_Sinus_ATTTID = beatsin8(30, 10, 15, 0, 0);// <- marche pas, Celui-ci marche -> beatsin8(15, 80, 255);
ATTTIDloop();
}
void ATTTIDStartEffect()
{
CurrentState = 0;
//Fill the colorIndex array with random numbers
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i] = random8();
}
// shutdown the K
FastLED.clear();
FastLED.show();
//_pKLeds->KOff();
}
void ATTTIDsetEffect()
{
// Colorer chaque pixel de la palette en utilisant l'index de colorIndex[]
for (int x = 0; x < kMatrixWidth; x++) {
for (int y = 0; y < kMatrixHeight; y++) {
int index = XY(x, y); // Calculer l'index en utilisant la fonction XY()
if (index < NUM_LEDS) {
leds[index] = ColorFromPalette(attmyPal, colorIndex[index], Current_Sinus_ATTTID);
}
}
}
FastLED.show();
}
void ATTTIDloop()
{
switch (CurrentState) {
case 0:
{
// Fixe l'effet principal
ATTTIDsetEffect();
CurrentState = 1; // va à l'étape 1
millis_fromset = millis();
break;
}
case 1:
{
// Attend 2ms avant de décaler le dégradé
if (millis() - millis_fromset >= 2) {
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i] = colorIndex[i]+1;
}
// et repasser à l'étape 0
CurrentState = 0;
}
// Mais en attendant le décalage, on fixe l'effet en fonction de Current_Sinus_ATTTID
ATTTIDsetEffect();
break;
}
}
}