#include <FastLED.h>
#include <IRremote.h>
// Hardware SPI - data 51, clock 53 pour la mega https://github.com/FastLED/FastLED/wiki/SPI-Hardware-or-Bit-banging
const byte nombreDeLeds = 40;
const byte dataPin = 51;
const byte clockPin = 53;
//
const byte IRPin = 9; // sur MEGA 5, 6, 9, 11, 46
CRGB leds[nombreDeLeds];
IRrecv receiver(IRPin);
const unsigned long deltaT = 10;
bool enPause = true;
unsigned long duree = 250;
uint8_t hue = 128;
void animation() {
static unsigned long chrono;
static byte currentLed = 0;
if (enPause) return;
if (millis() - chrono >= duree) {
if (currentLed > 1) leds[currentLed - 1] = CHSV( hue, 128, 100);
leds[currentLed] = CHSV( hue, 255, 200);
if (currentLed < nombreDeLeds - 1) leds[currentLed + 1] = CHSV( hue, 128, 100);
chrono = millis();
currentLed = (currentLed + 1) % nombreDeLeds;
FastLED.show();
FastLED.clear();
}
}
void interpretationCodeIR() {
switch (receiver.decodedIRData.command) {
case 162: Serial.println(F("POWER")); break;
case 226: Serial.println(F("MENU")); break;
case 34: Serial.println(F("TEST")); break;
case 194: Serial.println(F("BACK")); break;
case 224: Serial.println(F("PREV.")); break;
case 168: Serial.println(F("PLAY")); break;
case 144: Serial.println(F("NEXT")); break;
case 2: Serial.println(F("PLUS")); enPause = false; if (duree >= deltaT) duree -= deltaT; Serial.print(F("duree=")); Serial.println(duree); break;
case 152: Serial.println(F("MINUS")); enPause = false; duree += deltaT; Serial.print(F("duree=")); Serial.println(duree); break;
case 104: Serial.println(F("num: 0")); enPause = false; hue = 25; break;
case 48: Serial.println(F("num: 1")); enPause = false; hue = 50; break;
case 24: Serial.println(F("num: 2")); enPause = false; hue = 75; break;
case 122: Serial.println(F("num: 3")); enPause = false; hue = 100; break;
case 16: Serial.println(F("num: 4")); enPause = false; hue = 125; break;
case 56: Serial.println(F("num: 5")); enPause = false; hue = 150; break;
case 90: Serial.println(F("num: 6")); enPause = false; hue = 175; break;
case 66: Serial.println(F("num: 7")); enPause = false; hue = 200; break;
case 74: Serial.println(F("num: 8")); enPause = false; hue = 225; break;
case 82: Serial.println(F("num: 9")); enPause = false; hue = 255; break;
case 176: Serial.println(F("key: C")); //no break
default: enPause = true; FastLED.clear(); FastLED.show(); break;
}
}
void setup() {
Serial.begin(115200);
FastLED.addLeds<DOTSTAR, dataPin, clockPin >(leds, nombreDeLeds);
FastLED.setBrightness(50);
receiver.enableIRIn();
}
void loop() {
if (receiver.decode()) {
interpretationCodeIR();
receiver.resume();
}
animation(); // appel non bloquant
}