indentation + doc

This commit is contained in:
Julien Cabillot 2017-03-12 01:52:13 +01:00 committed by Cabillot Julien
parent cec7d7140e
commit 04e2bf3de1

View File

@ -14,7 +14,7 @@ int brightness = LED_BRIGHTNESS_DEFAULT;
int color = LED_COLOR_DEFAULT; int color = LED_COLOR_DEFAULT;
int speed = LED_SPEED_DEFAULT; int speed = LED_SPEED_DEFAULT;
CRGB leds[LED_NUM]; CRGB leds[LED_NUM];
String ledEffect = LED_EFFECT_CYLON; String ledEffect = LED_EFFECT_ERROR;
boolean ledState = false; boolean ledState = false;
// WIFI // WIFI
@ -45,21 +45,21 @@ void setup()
Serial.println("Ready"); Serial.println("Ready");
/* MQTT /* MQTT
* Il est important de faire un loop avant toute chose, * Il est important de faire un loop avant toute chose,
* afin de récupérer les valeurs provenant du broker mqtt * afin de récupérer les valeurs provenant du broker mqtt
* et pas démarrer avec de vieilles infos. * et pas démarrer avec de vieilles infos.
*/ */
for (short int i = 0; i < 10; i++) { for (short int i = 0; i < 10; i++) {
delay(200); delay(200);
client.loop(); client.loop();
} }
//////////////////////////////// ColorPalette /////////////////////////////// //////////////////////////////// ColorPalette ///////////////////////////////
currentPalette = RainbowColors_p; currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND; currentBlending = LINEARBLEND;
//////////////////////////////// ColorPalette /////////////////////////////// //////////////////////////////// ColorPalette ///////////////////////////////
Serial.println("End of setup"); Serial.println("End of setup");
} }
// WIFI // WIFI
@ -149,111 +149,120 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
} }
// LED // LED
/**
* Coupe tout le strip de led.
*/
void ledBlackAll() void ledBlackAll()
{ {
FastLED.clear(); FastLED.clear();
FastLED.show(); FastLED.show();
} }
/**
* Effet Cylon : défilement d'une simple led sur le strip aller/retour.
* Pour faire plus sympas on ajoute une lueur autour, avec une lumière atténué.
*/
void ledCylon() void ledCylon()
{ {
// Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante for(int i = 0; i < LED_NUM; i++) {
for(int i = 0; i < LED_NUM; i++) { client.loop();
client.loop();
if (ledEffect != LED_EFFECT_CYLON) { if (ledEffect != LED_EFFECT_CYLON) {
return; return;
}
if ((i - 3) >= 0) {
leds[i - 3] = CRGB::Black;
}
if ((i - 2) >= 0) {
/*
* Se lit 128/256 d'intensité lumineuse actuelle
* https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors
*/
leds[i - 2].fadeLightBy(240);
}
if ((i - 1) >= 0) {
leds[i - 1].fadeLightBy(200);
}
leds[i] = color;
if ((i + 1) <= LED_NUM) {
leds[i + 1] = color;
// Je suis volontairement un peu moins puissant sur l'avant
// pour donner un effet de trainée sur l'arrière
leds[i + 1].fadeLightBy(220);
}
if ((i + 2) <= LED_NUM) {
leds[i + 2] = color;
leds[i + 2].fadeLightBy(240);
}
FastLED.delay(1000 / speed);
} }
// led[0] et led[255] sont gérées par la loop précédante if ((i - 3) >= 0) {
for(int i = LED_NUM - 1; i > 0; i--) { leds[i - 3] = CRGB::Black;
client.loop(); }
if ((i - 2) >= 0) {
if (ledEffect != LED_EFFECT_CYLON) { /*
return; * Se lit 128/256 d'intensité lumineuse actuelle
} * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors
*/
if ((i - 2) >= 0) { leds[i - 2].fadeLightBy(240);
leds[i - 2] = color; }
leds[i - 2].fadeLightBy(240); if ((i - 1) >= 0) {
} leds[i - 1].fadeLightBy(200);
if ((i - 1) >= 0) {
leds[i - 1] = color;
leds[i - 1].fadeLightBy(220);
}
leds[i] = color;
if ((i + 1) <= LED_NUM) {
leds[i + 1].fadeLightBy(200);
}
if ((i + 2) <= LED_NUM) {
leds[i + 2].fadeLightBy(240);
}
if ((i + 3) <= LED_NUM) {
leds[i + 3] = CRGB::Black;
}
FastLED.delay(1000 / speed);
} }
}
void ledError() leds[i] = color;
{
for(int i = 0; i < LED_NUM; i++) { if ((i + 1) <= LED_NUM) {
if ((i % 2) == 0) { leds[i + 1] = color;
leds[i] = CRGB::Black; // Je suis volontairement un peu moins puissant sur l'avant
} else { // pour donner un effet de trainée sur l'arrière
leds[i] = CRGB::Red; leds[i + 1].fadeLightBy(220);
} }
if ((i + 2) <= LED_NUM) {
leds[i + 2] = color;
leds[i + 2].fadeLightBy(240);
} }
FastLED.delay(1000 / speed); FastLED.delay(1000 / speed);
}
// led[0] et led[255] sont gérées par la loop précédante
for(int i = LED_NUM - 1; i > 0; i--) {
client.loop();
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
if ((i - 2) >= 0) {
leds[i - 2] = color;
leds[i - 2].fadeLightBy(240);
}
if ((i - 1) >= 0) {
leds[i - 1] = color;
leds[i - 1].fadeLightBy(220);
}
leds[i] = color;
if ((i + 1) <= LED_NUM) {
leds[i + 1].fadeLightBy(200);
}
if ((i + 2) <= LED_NUM) {
leds[i + 2].fadeLightBy(240);
}
if ((i + 3) <= LED_NUM) {
leds[i + 3] = CRGB::Black;
}
FastLED.delay(1000 / speed);
}
}
/**
* Utilise pour indiquer une erreur sur la reception de l'effet.
*/
void ledError()
{
for(int i = 0; i < LED_NUM; i++) {
if ((i % 2) == 0) {
leds[i] = CRGB::Black;
} else {
leds[i] = CRGB::Red;
}
}
FastLED.delay(1000 / speed);
} }
void ledFullColor() void ledFullColor()
{ {
fill_solid(leds, LED_NUM, color); fill_solid(leds, LED_NUM, color);
// TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness
// Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
// Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2)
// 0.36787944 ?? censé correspondre au minimum // 0.36787944 ?? censé correspondre au minimum
// 108.4 ?? censé correspondre au maximum // 108.4 ?? censé correspondre au maximum
int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4;
Serial.print(breath); Serial.print(breath);
Serial.println(" / 255"); Serial.println(" / 255");
FastLED.setBrightness(breath); FastLED.setBrightness(breath);
FastLED.delay(100 / speed); FastLED.delay(100 / speed);
} }
///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// ///////////////////// FastLED-3.1.5/examples/ColorPalette /////////////////////