My code has progressed well. it is now functional with the animations I wanted.
there is still a small problem. During the "task_rest" which manages my two animation, I note that the rainbow effect makes a small pause when the fade effect is executed.
Can someone tell me more?
#include <Adafruit_NeoPixel.h>
#define LED1_PIN11 11
#define LED1_NUM 64
#define LED2_PIN12 12
#define LED2_NUM 16
#define BOUTON_PIN 2
boolean etatBouton;
const long pauseIntervalle = 10000;
int rainbowCyclesInterval = 12;
int long fadeIntervalle = 3200;
int rainbowCycles = 0;
int rainbowCycleCycles = 0;
int fade = 0;
int fadeFade = 0;
unsigned long rainbowCyclesPreviousMillis=0;
unsigned long fadePreviousMillis = 0;
long debutPauseIntervalle;
long temps;
long tempsBreath;
long tempsRainbow;
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(LED1_NUM, LED1_PIN11, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(LED2_NUM, LED2_PIN12, NEO_GRB + NEO_KHZ800);
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Serial.begin(9600);
pinMode(BOUTON_PIN, INPUT_PULLUP);
etatBouton = HIGH;
strip1.begin();
strip2.begin();
strip1.setBrightness(70);
strip2.setBrightness(70);
strip1.show();
strip2.show();
temps = millis();
}
void loop(){
etatBouton = digitalRead(BOUTON_PIN);
// Serial.println();
// Serial.println();
task_alive();
task_rest();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void task_alive(){
if((etatBouton == LOW)){ //Bouton Appuyé
strip1.fill(strip1.Color(255,0,0),0,LED1_NUM);
strip2.fill(strip2.Color(255,255,255),0,LED2_NUM);
strip1.show();
strip2.show();
temps = millis(); // Enregistre le temps
debutPauseIntervalle = temps;
}
if((etatBouton == HIGH) && (millis() - debutPauseIntervalle <= pauseIntervalle)){
strip1.fill(strip1.Color(255,0,0),0,LED1_NUM);
strip2.fill(strip2.Color(255,255,255),0,LED2_NUM);
strip1.show();
strip2.show();
temps = millis();
}
}
void task_rest(){
if((etatBouton == HIGH) && (millis() - debutPauseIntervalle > pauseIntervalle)){ //Bouton Relaché
if((unsigned long)(millis() - rainbowCyclesPreviousMillis) >= rainbowCyclesInterval) {
rainbowCyclesPreviousMillis = millis();
rainbowCycle();
}
if((unsigned long)(millis() - fadePreviousMillis) >= fadeIntervalle){
fadePreviousMillis = millis();
Fade(255, 0, 0, fadeIntervalle);
}
temps = millis();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void rainbowCycle() {
uint16_t i;
//for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip2.numPixels(); i++) {
strip2.setPixelColor(i, Wheel(((i * 256 / strip2.numPixels()) + rainbowCycleCycles) & 255));
}
strip2.show();
rainbowCycleCycles++;
if(rainbowCycleCycles >= 256*5) rainbowCycleCycles = 0;
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip2.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip2.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip2.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void Fade(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait){
for(uint8_t b = 0; b <255; b++) {
for(uint8_t i=0; i < strip1.numPixels(); i++) {
strip1.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
}
strip1.show();
wait = fadeIntervalle;
fadeFade++;
if(fadeFade >= 256*5) fadeFade = 0;
}
for(uint8_t b=255; b > 0; b--) {
for(uint8_t i = 0; i < strip1.numPixels(); i++) {
strip1.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
}
strip1.show();
wait = fadeIntervalle;
fadeFade++;
if(fadeFade >= 256*5) fadeFade = 0;
}
}