Skip to content

Instantly share code, notes, and snippets.

@rlogiacco
Last active November 17, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlogiacco/db551fbf2777683645efa4129bd00131 to your computer and use it in GitHub Desktop.
Save rlogiacco/db551fbf2777683645efa4129bd00131 to your computer and use it in GitHub Desktop.
Innov@ction
#include "Arduino.h"
#include <FastLED.h>
#include <elapsedMillis.h>
#include <FormattingSerialDebug.h>
#define PIN_LEGENDA 2
#define PIN_PLASTICO 3
#define NUM_STANZE 13
#define LED_COUNT_LEGENDA 13
#define LED_COUNT_PLASTICO 29
#define TEMPO_PER_STANZA 1500
#define TEMPO_PER_EFFETTO 5000
CRGB legenda[LED_COUNT_LEGENDA];
CRGB plastico[LED_COUNT_PLASTICO];
struct Stanza {
int leds[3];
int pannello;
CRGB colore;
};
Stanza stanze[NUM_STANZE];
void setup() {
SERIAL_DEBUG_SETUP(9600);
FastLED.addLeds<WS2812, PIN_LEGENDA, GRB>(legenda, LED_COUNT_LEGENDA);
FastLED.addLeds<WS2812, PIN_PLASTICO, GRB>(plastico, LED_COUNT_PLASTICO);
FastLED.setCorrection(LEDColorCorrection::TypicalLEDStrip);
FastLED.setBrightness(50);
stanze[0] = { {0, 1, -1}, 0, CRGB::Red };
stanze[1] = { {2, 3, -1}, 1, CRGB::Violet };
stanze[2] = { {4, 5, -1}, 2, CRGB::Orange };
stanze[3] = { {6, 7, -1}, 3, CRGB::Green };
stanze[4] = { {8, 9, -1}, 4, CRGB::Blue };
stanze[5] = { {10, 11, -1}, 5, CRGB::Yellow };
stanze[6] = { {12, 13, -1}, 6, CRGB::Aquamarine };
stanze[7] = { {14, 15, -1}, 7, CRGB::OrangeRed };
stanze[8] = { {16, 17, -1}, 8, CRGB::Purple };
stanze[9] = { {18, 19, -1}, 9, CRGB::PaleGreen };
stanze[10] = { {20, -1, -1}, 10, CRGB::Crimson };
stanze[11] = { {24, -1, -1}, 11, CRGB::BlueViolet };
stanze[12] = { {21, 22, 23}, 12, CRGB::Black };
rainbow();
}
byte looper = 0;
void loop() {
looper++;
for (byte i = 0; i < NUM_STANZE; i++) {
DEBUG("Stanza %u", i);
Stanza stanza = stanze[i];
if (!stanza.colore) {
DEBUG("Stanza BRAND");
unsigned long brand = millis();
byte hue = 0;
byte gap = 255 / 3;
while (millis() - brand < TEMPO_PER_STANZA) {
legenda[stanza.pannello] = CRGB(CHSV(hue, 255, 255));
plastico[stanza.leds[0]] = CRGB(CHSV(hue, 255, 255));
plastico[stanza.leds[1]] = CRGB(CHSV(hue + gap, 255, 255));
plastico[stanza.leds[2]] = CRGB(CHSV(hue + (2 * gap), 255, 255));
FastLED.show();
FastLED.delay(1000 / 3);
hue += gap;
}
} else {
legenda[stanza.pannello] = stanza.colore;
for (byte j = 0; j < 3; j++) {
if (stanza.leds[j] > -1) {
DEBUG("LED %u : %u %u %u", stanza.leds[j], stanza.colore.r, stanza.colore.g, stanza.colore.b);
plastico[stanza.leds[j]] = stanza.colore;
}
}
FastLED.show();
FastLED.delay(TEMPO_PER_STANZA);
}
// spegni stanza
legenda[stanza.pannello] = CRGB::Black;
for (byte j = 0; j < 3; j++) {
if (stanza.leds[j] > -1) {
plastico[stanza.leds[j]] = CRGB::Black;
}
}
}
looper % 2 ? snake() : rainbow();
}
#define FATTORE_GLITTER 80
#define FATTORE_TONALITA 20
void rainbow() {
DEBUG("Rainbow");
static byte hue = 0;
unsigned long time = millis();
while (millis() - time < TEMPO_PER_EFFETTO) {
fill_rainbow(plastico, LED_COUNT_PLASTICO, hue, FATTORE_TONALITA);
fill_rainbow(legenda, LED_COUNT_LEGENDA, hue, FATTORE_TONALITA);
if( random8() < FATTORE_GLITTER) {
plastico[ random16(LED_COUNT_PLASTICO) ] += CRGB::White;
legenda[ random16(LED_COUNT_LEGENDA) ] += CRGB::White;
}
FastLED.show();
FastLED.delay(1000 / 120);
hue += 2;
}
FastLED.clear(true));
}
void inline fade(CRGB* leds, byte count) {
for(int i = 0; i < count; i++) {
leds[i].nscale8(250);
}
}
void snake() {
static byte hue = 0;
unsigned long time = millis();
long index = 0;
while (millis() - time < TEMPO_PER_EFFETTO) {
plastico[index % LED_COUNT_PLASTICO] = CHSV(hue++, 255, 255);
legenda[index % LED_COUNT_LEGENDA] = CHSV(hue++, 255, 255);
FastLED.show();
fade(plastico, LED_COUNT_PLASTICO);
fade(legenda, LED_COUNT_LEGENDA);
FastLED.delay(1000 / 120);
index++;
}
FastLED.clear(true);
}
void test() {
for (byte i = 0; i < NUM_STANZE; i++) {
Stanza stanza = stanze[i];
legenda[stanza.pannello] = stanza.colore;
for (byte j = 0; j < 3; j++) {
if (stanza.leds[j] > -1) {
DEBUG("Stanza %u - LED %u - Indice %u", i, j, stanza.leds[j]);
plastico[stanza.leds[j]] = stanza.colore;
FastLED.show();
FastLED.delay(1000);
plastico[stanza.leds[j]] = CRGB::Black;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment