Problème extinction ruban led

Bonjour à tous je ne comprend pas pourquoi dans mon programme lorsque l'interrupteur envoie l'infos LOW ça ne coupe pas le ruban led instantanément, il s'éteint à la fin du programme.

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>

//==============================================Adafruit
#include <Adafruit_NeoPixel.h>
#define nb_led 180                                         // le module comporte 8 led
const int led = 47;
Adafruit_NeoPixel module = Adafruit_NeoPixel(nb_led, led, NEO_GRB + NEO_KHZ800);  // création de l'objet module

//==============================================FastLED
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN    47
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    80
CRGB leds[NUM_LEDS];
#define BRIGHTNESS         255
#define FRAMES_PER_SECOND  120


unsigned long previousMillis = 0; 
const long interval = 100; 

uint8_t gHue = 0; // rotating "base color" used by many of the patterns

// ========================================Variable Romain
         // variable qui enregistre l'état du bouton

//=========================================
// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
#define CHANNEL 1 

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2 

// Defines GPIO 13 as LED_1.
#define LED_1 13 

// Defines GPIO 12 as LED_2.
#define LED_2 12 

// ======================================== Variables for PWM settings.
const int PWM_freq = 5000;
const int PWM_Channel = 0;
const int PWM_resolution = 8;

// ======================================== Structure example to receive data.
// Must match the sender structure
typedef struct struct_message_receive {
  int receive_GPIO_num;
  int receive_Val;
} struct_message_receive;

// Create a struct_message to receive data.
struct_message_receive receive_Data;
// ========================================

// ________________________________________________________________________________ Callback when data is received.
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  digitalWrite(ON_Board_LED, HIGH); //--> Turn on ON_Board_LED.

  // ---------------------------------------- Get the MAC ADDRESS of the sender / slave.
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  // ---------------------------------------- 

  memcpy(&receive_Data, incomingData, sizeof(receive_Data)); //--> Copy the information in the "incomingData" variable into the "receive_Data" structure variable.

  // ---------------------------------------- Prints the MAC ADDRESS of sender / Master and Bytes received.
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Packet received from: ");
  Serial.println(macStr);
  Serial.print("Bytes received: ");
  Serial.println(len);
  // ---------------------------------------- 

  // ---------------------------------------- Conditions for controlling the LEDs.
  if (receive_Data.receive_GPIO_num == 13) digitalWrite(LED_1, receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 12) {
    int pwm = map(receive_Data.receive_Val, 0, 10, 0, 255);
    ledcWrite(PWM_Channel, pwm);  
  }
  // ---------------------------------------- 
  
  // ---------------------------------------- Prints all data received from the sender / Master.
  Serial.println("Receive Data: ");
  Serial.println(receive_Data.receive_GPIO_num);
  Serial.println(receive_Data.receive_Val);
  Serial.println("<<<<<");
  // ---------------------------------------- 

  digitalWrite(ON_Board_LED, LOW); //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(115200);
  Serial.println();

  pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, LOW); //--> Turn off Led On Board

  pinMode(LED_1,OUTPUT); //--> LED_1 port Direction output

  pinMode(LED_2,OUTPUT); //--> LED_2 port Direction output

  // ---------------------------------------- PWM settings.
  ledcSetup(PWM_Channel, PWM_freq, PWM_resolution);
  ledcAttachPin(LED_2, PWM_Channel);
  // ----------------------------------------

  // ---------------------------------------- Set Wi-Fi as Wifi Station Mode.
  WiFi.mode(WIFI_STA);
  // ----------------------------------------

  // ---------------------------------------- Set the Wi-Fi channel.
  // "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
  
  int cur_WIFIchannel = WiFi.channel();

  if (cur_WIFIchannel != CHANNEL) {
    //WiFi.printDiag(Serial); // Uncomment to verify channel number before
    esp_wifi_set_promiscuous(true);
    esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
    esp_wifi_set_promiscuous(false);
    //WiFi.printDiag(Serial); // Uncomment to verify channel change after
  }

  Serial.println("-------------");
  Serial.print("Wi-Fi channel : ");
  Serial.println(WiFi.channel());
  Serial.println("-------------");
  // ---------------------------------------- 

  // ---------------------------------------- Init ESP-NOW
  Serial.println("-------------");
  Serial.println("Start initializing ESP-NOW...");
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    Serial.println("Restart ESP32...");
    Serial.println("-------------");
    delay(1000);
    ESP.restart();
  }
  Serial.println("Initializing ESP-NOW was successful.");
  Serial.println("-------------");
  // ---------------------------------------- 

  // ---------------------------------------- Register for a callback function that will be called when data is received
  Serial.println();
  Serial.println("Register for a callback function that will be called when data is received");
  esp_now_register_recv_cb(OnDataRecv);
  // ----------------------------------------

  pinMode(led, OUTPUT);   // Initialise la led comme sortie
  //========================================================FastLED
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  unsigned long previousMillis = 0; 
  const long interval = 100; 

}

void loop() {

int etatLED_1 = digitalRead(LED_1);

  unsigned long currentMillis = millis();

  if (etatLED_1 == HIGH){

    for (int i = 0; i< 6; i++) {  

      for(int i=0;i<80;i++)                                    
        module.setPixelColor(i,150,150,150); //blanc
        module.show();
        while(millis() - currentMillis < interval) {}
        currentMillis = millis();

      for(int i=0;i<80;i++)
        module.setPixelColor(i,0,0,0); 
        module.show();
        while(millis() - currentMillis < interval) {}
        currentMillis = millis();
      }
      for ( int i = 0; i<= 79; i++) {
        module.setPixelColor(i,0,0,255); 
        module.show();
        while(millis() - currentMillis < interval) {}
        currentMillis = millis();
      }
  }

else {
  for(int i=0;i<180;i++) {                                       
    module.setPixelColor(i,0,0,0); 
    module.show();
  }
}

}

Essaye de bien formatter ton code, les balises codes sont mal placées.

Ce bloc est différent des deux précédents. L'attente est incluse dans la boucle ce qui fait qu'elle est plus lente que les deux autres. Est-ce que c'est voulu ?
C'est juste la présence de l'accolade à la fin qui change tout.

Ici tu n'as pas besoin de mettre le show dans la boucle puisque tu veux tout éteindre d'un seul coup. Ceci suffit :

for(int i=0;i<180;i++) module.setPixelColor(i,0,0,0);
module.show();

L'instruction for crée une boucle dans laquelle sera exécuté un certain nombre d'instructions. Si tu n'as qu'une seule instruction, tu peux ne pas mettre d'accolade :

for(int i=0;i<180;i++) 
module.setPixelColor(i,0,0,0);

Mais tu peux aussi les mettre :

for(int i=0;i<180;i++) {
  module.setPixelColor(i,0,0,0);
}

Ces deux écritures sont équivalentes, mais les puristes préfèrent la seconde.

Si tu as plusieurs instructions à exécuter en boucle, il faut les mettre entre accolades (les accolades définissent le bloc d'instructions à exécuter en boucle). C'est ce que tu as fait ici :

Note que ceci :

    while(millis() - currentMillis < interval) {}
    currentMillis = millis();

est équivalent à un simple
delay(interval);

On dit souvent qu'il vaut mieux éviter le delay qui est bloquant, mais là tu fais la même chose qu'un delay.

Merci pour ta réponse déjà !
Alors pour le 180 c'était une erreur de frappe, après j'ai essayé de formatter mon code comme tu dis pour le moment j'ai fait que le void loop().
Sinon j'utilise la fonction millis car mon interrupteur ne fonctionné déjà pas avec les delay.
Je joins le code d'origine tout fonctionne comme j'ai paramétré sauf l'interruption...

/*
 * Reference :
 * - ESP32: ESP-NOW Web Server Sensor Dashboard (ESP-NOW + Wi-Fi) : https://randomnerdtutorials.com/esp32-esp-now-wi-fi-web-server/
 * - ESP-NOW with ESP32: Send Data to Multiple Boards (one-to-many) : https://randomnerdtutorials.com/esp-now-one-to-many-esp32-esp8266/
 * - ESP32 Async Web Server – Control Outputs with Arduino IDE (ESPAsyncWebServer library) : https://randomnerdtutorials.com/esp32-async-web-server-espasyncwebserver-library/
 * - and from several other sources.
 */

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>
//==============================================Adafruit
#include <Adafruit_NeoPixel.h>
#define nb_led 180                                         // le module comporte 8 led
const int led = 47;
Adafruit_NeoPixel module = Adafruit_NeoPixel(nb_led, led, NEO_GRB + NEO_KHZ800);  // création de l'objet module

//==============================================FastLED
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN    47
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    180
CRGB leds[NUM_LEDS];
#define BRIGHTNESS         255
#define FRAMES_PER_SECOND  120
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

// ========================================Variable Romain
int etatLED_1;         // variable qui enregistre l'état du bouton

//=========================================
// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
#define CHANNEL 1 

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2 

// Defines GPIO 13 as LED_1.
#define LED_1 13 

// Defines GPIO 12 as LED_2.
#define LED_2 12 

// ======================================== Variables for PWM settings.
const int PWM_freq = 5000;
const int PWM_Channel = 0;
const int PWM_resolution = 8;

// ======================================== Structure example to receive data.
// Must match the sender structure
typedef struct struct_message_receive {
  int receive_GPIO_num;
  int receive_Val;
} struct_message_receive;

// Create a struct_message to receive data.
struct_message_receive receive_Data;
// ========================================

// ________________________________________________________________________________ Callback when data is received.
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  digitalWrite(ON_Board_LED, HIGH); //--> Turn on ON_Board_LED.

  // ---------------------------------------- Get the MAC ADDRESS of the sender / slave.
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  // ---------------------------------------- 

  memcpy(&receive_Data, incomingData, sizeof(receive_Data)); //--> Copy the information in the "incomingData" variable into the "receive_Data" structure variable.

  // ---------------------------------------- Prints the MAC ADDRESS of sender / Master and Bytes received.
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Packet received from: ");
  Serial.println(macStr);
  Serial.print("Bytes received: ");
  Serial.println(len);
  // ---------------------------------------- 

  // ---------------------------------------- Conditions for controlling the LEDs.
  if (receive_Data.receive_GPIO_num == 13) digitalWrite(LED_1, receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 12) {
    int pwm = map(receive_Data.receive_Val, 0, 10, 0, 255);
    ledcWrite(PWM_Channel, pwm);  
  }
  // ---------------------------------------- 
  
  // ---------------------------------------- Prints all data received from the sender / Master.
  Serial.println("Receive Data: ");
  Serial.println(receive_Data.receive_GPIO_num);
  Serial.println(receive_Data.receive_Val);
  Serial.println("<<<<<");
  // ---------------------------------------- 

  digitalWrite(ON_Board_LED, LOW); //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(115200);
  Serial.println();

  pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, LOW); //--> Turn off Led On Board

  pinMode(LED_1,OUTPUT); //--> LED_1 port Direction output

  pinMode(LED_2,OUTPUT); //--> LED_2 port Direction output

  // ---------------------------------------- PWM settings.
  ledcSetup(PWM_Channel, PWM_freq, PWM_resolution);
  ledcAttachPin(LED_2, PWM_Channel);
  // ----------------------------------------

  // ---------------------------------------- Set Wi-Fi as Wifi Station Mode.
  WiFi.mode(WIFI_STA);
  // ----------------------------------------

  // ---------------------------------------- Set the Wi-Fi channel.
  // "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
  
  int cur_WIFIchannel = WiFi.channel();

  if (cur_WIFIchannel != CHANNEL) {
    //WiFi.printDiag(Serial); // Uncomment to verify channel number before
    esp_wifi_set_promiscuous(true);
    esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
    esp_wifi_set_promiscuous(false);
    //WiFi.printDiag(Serial); // Uncomment to verify channel change after
  }

  Serial.println("-------------");
  Serial.print("Wi-Fi channel : ");
  Serial.println(WiFi.channel());
  Serial.println("-------------");
  // ---------------------------------------- 

  // ---------------------------------------- Init ESP-NOW
  Serial.println("-------------");
  Serial.println("Start initializing ESP-NOW...");
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    Serial.println("Restart ESP32...");
    Serial.println("-------------");
    delay(1000);
    ESP.restart();
  }
  Serial.println("Initializing ESP-NOW was successful.");
  Serial.println("-------------");
  // ---------------------------------------- 

  // ---------------------------------------- Register for a callback function that will be called when data is received
  Serial.println();
  Serial.println("Register for a callback function that will be called when data is received");
  esp_now_register_recv_cb(OnDataRecv);
  // ----------------------------------------

  pinMode(led, OUTPUT);   // Initialise la led comme sortie
  //========================================================FastLED
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() 
{
  etatLED_1 = digitalRead(LED_1); // On mémorise l'état du bouton

  

    if(etatLED_1 == LOW) // teste si le bouton a un niveau logique BAS
      {
        for(int i=0;i<180;i++)                                       // 180 premières led en bleu
        module.setPixelColor(i,0,0,0); 
        module.show(); 
      }
    else // teste si le bouton a un niveau logique différent de BAS (donc HAUT)
    { 
      for (int i = 0; i< 6; i++) {                                  // répéter le programme 6 fois

      for(int i=0;i<180;i++)                                       // 180 premières led en blanc
      module.setPixelColor(i,100,100,100); 
      module.show();
      delay(450);

      for(int i=0;i<180;i++)                                       // Black pause noir
      module.setPixelColor(i,0,0,0); 
      module.show();
      delay(1800);
      }
      for(int i=0;i<180;i++)                                       // Black pause noir
      module.setPixelColor(i,0,0,0); 
      module.show();
      delay(600);

      for(int i=0;i<180;i++)                                       // 180 led en blanc
      module.setPixelColor(i,100,100,100); 
      module.show();
      delay(1480);

      for(int i=0;i<180;i++)                                       // Black pause noir
      module.setPixelColor(i,0,0,0); 
      module.show();
      delay(450);

      for ( int i = 0; i<= 179; i++) {
      module.setPixelColor(i,0,0,255); 
      module.show();
      delay(32);
      }
      delay(4000);

      for (int i=0; i<1500; i++) { 
      for(int i=0;i<180;i++)                                   // 180 premières led en blanc
      module.setPixelColor(i,100,100,100); //===========================Blanc
      module.show();
      }
      for (int i=0; i<6000; i++){ 
      FastLED.show();  
      fadeToBlackBy( leds, NUM_LEDS, 30); //20 correspond à la trainé
      uint8_t dothue = 0;
      for( int i = 0; i < 8; i++) {
      leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
      dothue += 32; }
      }
      for (int i=0; i<6000; i++) { 
      FastLED.show();
      // insert a delay to keep the framerate modest
      FastLED.delay(1000/FRAMES_PER_SECOND); 
      // do some periodic updates
      EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
      // random colored speckles that blink in and fade smoothly
      fadeToBlackBy( leds, NUM_LEDS, 10);
      int pos = random16(NUM_LEDS);
      leds[pos] += CHSV( gHue + random8(64), 200, 255);
      }
    

    }

Deux boucles imbriquées avec la même variable, ça ne peut pas marcher...

Je ne comprends pas ce qu'est ton interrupteur. C'est sur la pin LED_1 ? Elle est déclarée en OUTPUT...

Pour savoir ce qui se passe, tu devrais ajouter des Serial.print :

  etatLED_1 = digitalRead(LED_1); // On mémorise l'état du bouton
  Serial.print("Etat LED_1 = ");
  Serial.println(etatLED_1);

Bonjour,

Ca va marcher, mais ce n'est clairement pas recommandé.
Ce ne sont pas les mêmes variables. Le deuxième i existe uniquement dans la boucle intérieure et masque le i de la boucle extérieure dans cette boucle intérieure.

Alors oui la 1 er boucle qui contient les 1500 je sais pas se quel fais la, je vais essayer de la retirer.
Pour se qui est de Led_1 alors enfaite j’ai pris toute la base du code sur internet c’est ce qui me convenait le plus communication protocole ESP-NOW et serveur web.
Dans son exemple l’esclave porte deux Leds de couleur une led1 avec un commutateur et led2 un silder. ( moi pour le moment je n’utilise pas le silder.
Du coup pour lancer mon loop je récupère le signal en led_1.
Après ça lance bien mais ça n’éteint pas lol.
Je vais essayé avec les print pour voir. Merci

Je suis novice et loin d’être informaticien ou programmeur.

Ca n'a pas marché alors :frowning:
Je me suis permis de formatter complétement ton code et de rajouter des accolades à chaque "For", qui peuvent être une source d'erreur lorsqu'elles sont absentes.

/*
 * Reference :
 * - ESP32: ESP-NOW Web Server Sensor Dashboard (ESP-NOW + Wi-Fi) : https://randomnerdtutorials.com/esp32-esp-now-wi-fi-web-server/
 * - ESP-NOW with ESP32: Send Data to Multiple Boards (one-to-many) : https://randomnerdtutorials.com/esp-now-one-to-many-esp32-esp8266/
 * - ESP32 Async Web Server – Control Outputs with Arduino IDE (ESPAsyncWebServer library) : https://randomnerdtutorials.com/esp32-async-web-server-espasyncwebserver-library/
 * - and from several other sources.
 */

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>
//==============================================Adafruit
#include <Adafruit_NeoPixel.h>
#define nb_led 180  // le module comporte 8 led
const int led = 47;
Adafruit_NeoPixel module = Adafruit_NeoPixel(nb_led, led, NEO_GRB + NEO_KHZ800);  // création de l'objet module

//==============================================FastLED
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 47
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 180
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
uint8_t gHue = 0;  // rotating "base color" used by many of the patterns

// ========================================Variable Romain
int etatLED_1;  // variable qui enregistre l'état du bouton

//=========================================
// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
#define CHANNEL 1

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2

// Defines GPIO 13 as LED_1.
#define LED_1 13

// Defines GPIO 12 as LED_2.
#define LED_2 12

// ======================================== Variables for PWM settings.
const int PWM_freq = 5000;
const int PWM_Channel = 0;
const int PWM_resolution = 8;

// ======================================== Structure example to receive data.
// Must match the sender structure
typedef struct struct_message_receive {
  int receive_GPIO_num;
  int receive_Val;
} struct_message_receive;

// Create a struct_message to receive data.
struct_message_receive receive_Data;
// ========================================

// ________________________________________________________________________________ Callback when data is received.
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
  digitalWrite(ON_Board_LED, HIGH);  //--> Turn on ON_Board_LED.

  // ---------------------------------------- Get the MAC ADDRESS of the sender / slave.
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  // ----------------------------------------

  memcpy(&receive_Data, incomingData, sizeof(receive_Data));  //--> Copy the information in the "incomingData" variable into the "receive_Data" structure variable.

  // ---------------------------------------- Prints the MAC ADDRESS of sender / Master and Bytes received.
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Packet received from: ");
  Serial.println(macStr);
  Serial.print("Bytes received: ");
  Serial.println(len);
  // ----------------------------------------

  // ---------------------------------------- Conditions for controlling the LEDs.
  if (receive_Data.receive_GPIO_num == 13) digitalWrite(LED_1, receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 12) {
    int pwm = map(receive_Data.receive_Val, 0, 10, 0, 255);
    ledcWrite(PWM_Channel, pwm);
  }
  // ----------------------------------------

  // ---------------------------------------- Prints all data received from the sender / Master.
  Serial.println("Receive Data: ");
  Serial.println(receive_Data.receive_GPIO_num);
  Serial.println(receive_Data.receive_Val);
  Serial.println("<<<<<");
  // ----------------------------------------

  digitalWrite(ON_Board_LED, LOW);  //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  Serial.println();

  pinMode(ON_Board_LED, OUTPUT);    //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, LOW);  //--> Turn off Led On Board

  pinMode(LED_1, OUTPUT);  //--> LED_1 port Direction output

  pinMode(LED_2, OUTPUT);  //--> LED_2 port Direction output

  // ---------------------------------------- PWM settings.
  ledcSetup(PWM_Channel, PWM_freq, PWM_resolution);
  ledcAttachPin(LED_2, PWM_Channel);
  // ----------------------------------------

  // ---------------------------------------- Set Wi-Fi as Wifi Station Mode.
  WiFi.mode(WIFI_STA);
  // ----------------------------------------

  // ---------------------------------------- Set the Wi-Fi channel.
  // "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.

  int cur_WIFIchannel = WiFi.channel();

  if (cur_WIFIchannel != CHANNEL) {
    //WiFi.printDiag(Serial); // Uncomment to verify channel number before
    esp_wifi_set_promiscuous(true);
    esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
    esp_wifi_set_promiscuous(false);
    //WiFi.printDiag(Serial); // Uncomment to verify channel change after
  }

  Serial.println("-------------");
  Serial.print("Wi-Fi channel : ");
  Serial.println(WiFi.channel());
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Init ESP-NOW
  Serial.println("-------------");
  Serial.println("Start initializing ESP-NOW...");
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    Serial.println("Restart ESP32...");
    Serial.println("-------------");
    delay(1000);
    ESP.restart();
  }
  Serial.println("Initializing ESP-NOW was successful.");
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Register for a callback function that will be called when data is received
  Serial.println();
  Serial.println("Register for a callback function that will be called when data is received");
  esp_now_register_recv_cb(OnDataRecv);
  // ----------------------------------------

  pinMode(led, OUTPUT);  // Initialise la led comme sortie
  //========================================================FastLED
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  etatLED_1 = digitalRead(LED_1);  // On mémorise l'état du bouton



  if (etatLED_1 == LOW)  // teste si le bouton a un niveau logique BAS
  {
    for (int i = 0; i < 180; i++) {  // 180 premières led en bleu
      module.setPixelColor(i, 0, 0, 0);
    }
    module.show();
  } else  // teste si le bouton a un niveau logique différent de BAS (donc HAUT)
  {
    for (int i = 0; i < 6; i++) {  // répéter le programme 6 fois

      for (int i = 0; i < 180; i++) {  // 180 premières led en blanc
        module.setPixelColor(i, 100, 100, 100);
      }
      module.show();
      delay(450);

      for (int i = 0; i < 180; i++) {  // Black pause noir
        module.setPixelColor(i, 0, 0, 0);
      }
      module.show();
      delay(1800);
    }
    for (int i = 0; i < 180; i++) {  // Black pause noir
      module.setPixelColor(i, 0, 0, 0);
    }
    module.show();
    delay(600);

    for (int i = 0; i < 180; i++) {  // 180 led en blanc
      module.setPixelColor(i, 100, 100, 100);
    }
    module.show();
    delay(1480);

    for (int i = 0; i < 180; i++) {  // Black pause noir
      module.setPixelColor(i, 0, 0, 0);
    }
    module.show();
    delay(450);

    for (int i = 0; i <= 179; i++) {
      module.setPixelColor(i, 0, 0, 255);
      module.show();
      delay(32);
    }
    delay(4000);

    for (int i = 0; i < 180; i++) {            // 180 premières led en blanc
      module.setPixelColor(i, 100, 100, 100);  //===========================Blanc
    }
    module.show();
    
    for (int i = 0; i < 6000; i++) {
      FastLED.show();
      fadeToBlackBy(leds, NUM_LEDS, 30);  //20 correspond à la trainé
      uint8_t dothue = 0;
      for (int i = 0; i < 8; i++) {
        leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255);
        dothue += 32;
      }
    }
    for (int i = 0; i < 6000; i++) {
      FastLED.show();
      // insert a delay to keep the framerate modest
      FastLED.delay(1000 / FRAMES_PER_SECOND);
      // do some periodic updates
      EVERY_N_MILLISECONDS(20) {
        gHue++;
      }  // slowly cycle the "base color" through the rainbow
      // random colored speckles that blink in and fade smoothly
      fadeToBlackBy(leds, NUM_LEDS, 10);
      int pos = random16(NUM_LEDS);
      leds[pos] += CHSV(gHue + random8(64), 200, 255);
    }
  }

Tu veux dire que ton animation est jouée en boucle, même lorsque ta LED1 branché sur la broche 13 est éteinte ?

Je ne sais pas où tu as trouvé ce code, mais c'est une sacrée bouse !!!
Le ruban de leds est défini deux fois, avec deux bibliothèques différentes : j'ai jamais vu ça.

puis :

Et dans le code, ça continue : ici c'est Neopixel

Juste après c'est FastLED :

Moi, je suis déjà étonné qu'il se passe quelque chose...

Je ne sais pas où tu as trouvé ce code, mais c'est une sacrée bouse !!!
Le ruban de leds est défini deux fois, avec deux bibliothèques différentes : j'ai jamais vu ça.

Le code viens de YouTube, mais par contre dire que c'est "une sacrée bouse " la ce n'est pas cool !
De base je voulais utiliser qu'une librairie donc utiliser les identifiants qu'une fois !
Mais pas le choix les programmes qui me conviennent sont dans les deux librairies et je n'est pas peur de dire que mes compétences pour la création ne sont pas au rendez-vous !
Voilà pourquoi l'utilisation de deux librairies !

[/quote]
Moi, je suis déjà étonné qu'il se passe quelque chose...
[/quote]
*Mais oui tout fonctionne comme j'ai envie ! Sauf l'interruption *

voici un liens vidéo du résultat :

[filtered-21C43034-364C-42ED-BFCF-3C68FFEF7892.MP4 - Google Drive]

Merci d'avoir formatter le code je les installer pour voir mais ça change rien. :sweat:
Pour répondre à ta question :"Tu veux dire que ton animation est jouée en boucle, même lorsque ta LED1 branché sur la broche 13 est éteinte ?"
Oui voilà c'est ça !

Du coup j'ai fait comme tu as dis voilà se qui se passe :

Au départ on a bien le print après le lancement on à le print à l'état 1, mais quand je coupe on voit bien que ma sortie 13 à changé d'état mais j'ai pas le print.
Et il revient des que la boucle est terminé....

Si tu n'a pas de deuxième ligne avec "Etat LED_1 = X", c'est que tu n'es pas sortie de ta fonction loop.

Que veut tu dire revient des que la boucle est terminé?

Ma ligne println Etat LED_1 = 0 ne revient pas aussitôt l'interruption établie alors que l'on vois bien la communication entre les ESP qui dis le message pin 13 = 0.
Mais quand mon programme loop est terminé la elle revient.

Désolé pour la bouse... :smirk:

Je ne comprends pas très bien : tu parles d'un bouton connecté sur la pin LED_1 : est-ce un bouton physique, genre bouton poussoir ?

image

Si oui, il devrait être défini en INPUT et pas en OUTPUT.
Ensuite, selon que tu veuilles détecter un LOW ou un HIGH lorsqu'il est enfoncé, tu dois ou non mettre INPUT_PULLUP.

Le plus simple est de faire :
pinMode(LED_1, INPUT_PULLUP);
et de le connecter entre GND et la pin LED_1. Comme ça, lorsque tu feras ton :
etatLED_1 = digitalRead(LED_1); // On mémorise l'état du bouton
la variable etatLED_1 sera LOW lorsqu'il est enfoncé et HIGH sinon.

Pour ta bande de leds, le plus simple serait d'utiliser FastLED, car tu utilises des fonctions complexes d'animation, et d'abandonner Adafruit_NeoPixel, car tu peux remplacer facilement les fonctions que tu utilises.

Par exemple :

    for (int i = 0; i < 180; i++) { 
      module.setPixelColor(i, 0, 0, 0);
    }
    module.show();

deviendrait :

    for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
    FastLED.show();

A tester car ça fait longtemps que je n'ai pas joué avec FastLED.
Tu as la liste des noms de couleurs ici :
https://fastled.io/docs/struct_c_r_g_b.html#aeb40a08b7cb90c1e21bd408261558b99

  • CRGB::Blue, CRGB::Black, CRGB::White, CRGB::Red, CRGB::Green sont les plus simples.

En relisant le code et les messages, je vois qu'il s'agit d'une LED qui est commandée dans ta callback : dans ce cas inutile de changer le OUTPUT. Tu devrais par contre ajouter des serial.print à cet endroit :

Serial.print("GPIO num = "); Serial.println(receive_Data.receive_GPIO_num);
Serial.print("GPIO val= "); Serial.println(receive_Data.receive_Val);
if (receive_Data.receive_GPIO_num == 13)  digitalWrite(LED_1, receive_Data.receive_Val);

Tu verras ainsi si la LED est bien mise à la bonne valeur.

Ba oui, tu lis ta broche 13, au début de la fonction loop, pas à la fin de l'interruption.
Du coup l'animation que tu lance lorsque tu as ta première interruption met combien de temps à s'exécuter ?
Si tu veux éteindre "immédiatement" ton animation, il ne faut pas que ton animation bloque ton programme pendant celle-ci.

TKT

Bon voici le résultat du code en FastLed :

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>

//==============================================FastLED
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 47
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 180
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
uint8_t gHue = 0;  // rotating "base color" used by many of the patterns

// ========================================Variable Romain
int etatLED_1;  // variable qui enregistre l'état du bouton

//=========================================
// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
#define CHANNEL 1

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2

// Defines GPIO 13 as LED_1.
#define LED_1 13

// Defines GPIO 12 as LED_2.
#define LED_2 12

// ======================================== Variables for PWM settings.
const int PWM_freq = 5000;
const int PWM_Channel = 0;
const int PWM_resolution = 8;

// ======================================== Structure example to receive data.
// Must match the sender structure
typedef struct struct_message_receive {
  int receive_GPIO_num;
  int receive_Val;
} struct_message_receive;

// Create a struct_message to receive data.
struct_message_receive receive_Data;
// ========================================

// ________________________________________________________________________________ Callback when data is received.
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
  digitalWrite(ON_Board_LED, HIGH);  //--> Turn on ON_Board_LED.

  // ---------------------------------------- Get the MAC ADDRESS of the sender / slave.
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  // ----------------------------------------

  memcpy(&receive_Data, incomingData, sizeof(receive_Data));  //--> Copy the information in the "incomingData" variable into the "receive_Data" structure variable.

  // ---------------------------------------- Prints the MAC ADDRESS of sender / Master and Bytes received.
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Packet received from: ");
  Serial.println(macStr);
  Serial.print("Bytes received: ");
  Serial.println(len);
  // ----------------------------------------

  // ---------------------------------------- Conditions for controlling the LEDs.
  Serial.print("GPIO num = "); Serial.println(receive_Data.receive_GPIO_num);
  Serial.print("GPIO val= "); Serial.println(receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 13) digitalWrite(LED_1, receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 12) {
    int pwm = map(receive_Data.receive_Val, 0, 10, 0, 255);
    ledcWrite(PWM_Channel, pwm);
  }
  // ----------------------------------------

  // ---------------------------------------- Prints all data received from the sender / Master.
  Serial.println("Receive Data: ");
  Serial.println(receive_Data.receive_GPIO_num);
  Serial.println(receive_Data.receive_Val);
  Serial.println("<<<<<");
  // ----------------------------------------

  digitalWrite(ON_Board_LED, LOW);  //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  Serial.println();

  pinMode(ON_Board_LED, OUTPUT);    //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, LOW);  //--> Turn off Led On Board

  pinMode(LED_1, OUTPUT);  //--> LED_1 port Direction output

  pinMode(LED_2, OUTPUT);  //--> LED_2 port Direction output

  // ---------------------------------------- PWM settings.
  ledcSetup(PWM_Channel, PWM_freq, PWM_resolution);
  ledcAttachPin(LED_2, PWM_Channel);
  // ----------------------------------------

  // ---------------------------------------- Set Wi-Fi as Wifi Station Mode.
  WiFi.mode(WIFI_STA);
  // ----------------------------------------

  // ---------------------------------------- Set the Wi-Fi channel.
  // "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.

  int cur_WIFIchannel = WiFi.channel();

  if (cur_WIFIchannel != CHANNEL) {
    //WiFi.printDiag(Serial); // Uncomment to verify channel number before
    esp_wifi_set_promiscuous(true);
    esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
    esp_wifi_set_promiscuous(false);
    //WiFi.printDiag(Serial); // Uncomment to verify channel change after
  }

  Serial.println("-------------");
  Serial.print("Wi-Fi channel : ");
  Serial.println(WiFi.channel());
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Init ESP-NOW
  Serial.println("-------------");
  Serial.println("Start initializing ESP-NOW...");
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    Serial.println("Restart ESP32...");
    Serial.println("-------------");
    delay(1000);
    ESP.restart();
  }
  Serial.println("Initializing ESP-NOW was successful.");
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Register for a callback function that will be called when data is received
  Serial.println();
  Serial.println("Register for a callback function that will be called when data is received");
  esp_now_register_recv_cb(OnDataRecv);
  // ----------------------------------------

  //========================================================FastLED
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  etatLED_1 = digitalRead(LED_1);  // On mémorise l'état du bouton
  Serial.print("Etat LED_1 = ");
  Serial.println(etatLED_1);


  if (etatLED_1 == LOW)  // teste si le bouton a un niveau logique BAS
  {
    for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
      FastLED.show();

  } else  // teste si le bouton a un niveau logique différent de BAS (donc HAUT)
  {
    for (int i = 0; i < 6; i++) {  // répéter le programme 6 fois

      for (int i = 0; i < 180; i++) leds[i] = CRGB::White;
        FastLED.show();
        delay(450);

      for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
        FastLED.show();
        delay(1800);
    }
    for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
      FastLED.show();
      delay(600);

    for (int i = 0; i < 180; i++) leds[i] = CRGB::White;
      FastLED.show();
      delay(1480);

    for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
      FastLED.show();
      delay(450);

    for (int i = 0; i <= 179; i++) { leds[i] = CRGB::Blue;
      FastLED.show();
      delay(32);
    }
    delay(4000);

    for (int i = 0; i < 180; i++) leds[i] = CRGB::Black;
      FastLED.show();
    
    for (int i = 0; i < 6000; i++) {
      FastLED.show();
      fadeToBlackBy(leds, NUM_LEDS, 30);  //20 correspond à la trainé
      uint8_t dothue = 0;
      for (int i = 0; i < 8; i++) {
        leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255);
        dothue += 32;
      }
    }
    for (int i = 0; i < 6000; i++) {
      FastLED.show();
      // insert a delay to keep the framerate modest
      FastLED.delay(1000 / FRAMES_PER_SECOND);
      // do some periodic updates
      EVERY_N_MILLISECONDS(20) {
        gHue++;
      }  // slowly cycle the "base color" through the rainbow
      // random colored speckles that blink in and fade smoothly
      fadeToBlackBy(leds, NUM_LEDS, 10);
      int pos = random16(NUM_LEDS);
      leds[pos] += CHSV(gHue + random8(64), 200, 255);
    }
  }
}

Mais du coup ça ne change rien niveau interrupteur !!!!

Voici mon interface Web Serveur :

Voici le moniteur série avec les résultats println on reçois bien l'information mais pourquoi ça coupe que à la fin de la boucle ? Bonne question lol ! :

L'animation dure 5 minutes en gros pour le moment.
Bah c'est pour ça que j'ai testé à millis(); , mais bon pas très concluant.
Après sur Discord quelqu'un ma parler de demander au programme de contrôler la nouvelle variable etatLED_1 pendant l'exécution du programme. Mais je sais pas comment faire ça lol et la personne plus de nouvelle pour le moment....

ba oui, mais tu as implanté la fonction "delay" avec la fonction "millis".
L'intérêt de la fonction "millis" est que bien utilisée tu ne fais une action uniquement si le temps est passé pendant que ton programme fait autre chose, au lieu d'attendre que le temps soit passé pour faire quelque chose.

Oui, mais cela veut dire en mettre un peu partout dans tes for, à chaque for en faite quasiment.
la méthode sale est d'insérer if (digitalRead(LED_1) == HIGH) return; au début de chaque boucle for

L'autre façon est de faire une machine à état ou un équivalent.
c'est à dire que ton animation se fasse en appelant une multitude de fois la fonction loop et que chaque appel prenne un minimum de temps.

On va déjà simplifier ce code, FastLED est très puissante donc autant s'en servir.

Pour éteindre toutes les leds :

FastLED.clear();

Pour mettre toutes les leds à la même couleur (ici en rouge) :

fill_solid( leds, NUM_LEDS, CRGB::Red);

Ca va te permettre d'ôter pas mal de lignes de code : plus besoin de boucle for pour ces instructions.
Bien sûr, tu fais le FastLED.show(); et le delay ensuite.

Tu peux même créer une fonction qui fera le job global : mettre toutes les leds à la même couleur, afficher et faire le delay.

void setLeds(CRGB couleur, int delai) {
  fill_solid(leds, NUM_LEDS, couleur);
  FastLED.show();
  delay(delai);
}

Et tu remplaces alors tous les blocs par l'appel de la fonction :

      for (int i = 0; i < 180; i++) leds[i] = CRGB::White;
        FastLED.show();
        delay(450);

devient
setLeds(CRGB::White, 450);
Si tu n'as pas de delay, tu mets 0.

Désolé de ne pas encore résoudre le problème du bouton, mais c'est pour y voir plus clair dans ton code. On va y venir petit à petit...

Bon alors j'ai modifié le code comme tu m'as dit sauf que la commande Fast LED.clear(); ne convient pas.
Je l'ai remplacé par fill solid( leds, NUM_LEDS, CRGB: : Black); est là ça fonctionne.

// ======================================== Including the libraries.
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>

//==============================================FastLED
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 17
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 180
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 150
#define FRAMES_PER_SECOND 120
uint8_t gHue = 0;  // rotating "base color" used by many of the patterns

// ========================================Variable Romain
int etatLED_1;  // variable qui enregistre l'état du bouton

//=========================================
// Defines the Wi-Fi channel.
// Configured channel range from 1~13 channels (by default).
// "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.
#define CHANNEL 1

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2

// Defines GPIO 13 as LED_1.
#define LED_1 13

// Defines GPIO 12 as LED_2.
#define LED_2 12

// ======================================== Variables for PWM settings.
const int PWM_freq = 5000;
const int PWM_Channel = 0;
const int PWM_resolution = 8;

// ======================================== Structure example to receive data.
// Must match the sender structure
typedef struct struct_message_receive {
  int receive_GPIO_num;
  int receive_Val;
} struct_message_receive;

// Create a struct_message to receive data.
struct_message_receive receive_Data;
// ========================================

// ________________________________________________________________________________ Callback when data is received.
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
  digitalWrite(ON_Board_LED, HIGH);  //--> Turn on ON_Board_LED.

  // ---------------------------------------- Get the MAC ADDRESS of the sender / slave.
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  // ----------------------------------------

  memcpy(&receive_Data, incomingData, sizeof(receive_Data));  //--> Copy the information in the "incomingData" variable into the "receive_Data" structure variable.

  // ---------------------------------------- Prints the MAC ADDRESS of sender / Master and Bytes received.
  Serial.println();
  Serial.println("<<<<< Receive Data:");
  Serial.print("Packet received from: ");
  Serial.println(macStr);
  Serial.print("Bytes received: ");
  Serial.println(len);
  // ----------------------------------------

  // ---------------------------------------- Conditions for controlling the LEDs.
  Serial.print("GPIO num = "); Serial.println(receive_Data.receive_GPIO_num);
  Serial.print("GPIO val= "); Serial.println(receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 13) digitalWrite(LED_1, receive_Data.receive_Val);
  if (receive_Data.receive_GPIO_num == 12) {
    int pwm = map(receive_Data.receive_Val, 0, 10, 0, 255);
    ledcWrite(PWM_Channel, pwm);
  }
  // ----------------------------------------

  // ---------------------------------------- Prints all data received from the sender / Master.
  Serial.println("Receive Data: ");
  Serial.println(receive_Data.receive_GPIO_num);
  Serial.println(receive_Data.receive_Val);
  Serial.println("<<<<<");
  // ----------------------------------------

  digitalWrite(ON_Board_LED, LOW);  //--> Turn off ON_Board_LED.
}
// ________________________________________________________________________________

// ________________________________________________________________________________ VOID SETUP()
void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  Serial.println();

  pinMode(ON_Board_LED, OUTPUT);    //--> On Board LED port Direction output
  digitalWrite(ON_Board_LED, LOW);  //--> Turn off Led On Board

  pinMode(LED_1, OUTPUT);  //--> LED_1 port Direction output

  pinMode(LED_2, OUTPUT);  //--> LED_2 port Direction output

  // ---------------------------------------- PWM settings.
  ledcSetup(PWM_Channel, PWM_freq, PWM_resolution);
  ledcAttachPin(LED_2, PWM_Channel);
  // ----------------------------------------

  // ---------------------------------------- Set Wi-Fi as Wifi Station Mode.
  WiFi.mode(WIFI_STA);
  // ----------------------------------------

  // ---------------------------------------- Set the Wi-Fi channel.
  // "ESP32 Master" and "ESP32 Slaves" must use the same Wi-Fi channel.

  int cur_WIFIchannel = WiFi.channel();

  if (cur_WIFIchannel != CHANNEL) {
    //WiFi.printDiag(Serial); // Uncomment to verify channel number before
    esp_wifi_set_promiscuous(true);
    esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
    esp_wifi_set_promiscuous(false);
    //WiFi.printDiag(Serial); // Uncomment to verify channel change after
  }

  Serial.println("-------------");
  Serial.print("Wi-Fi channel : ");
  Serial.println(WiFi.channel());
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Init ESP-NOW
  Serial.println("-------------");
  Serial.println("Start initializing ESP-NOW...");
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    Serial.println("Restart ESP32...");
    Serial.println("-------------");
    delay(1000);
    ESP.restart();
  }
  Serial.println("Initializing ESP-NOW was successful.");
  Serial.println("-------------");
  // ----------------------------------------

  // ---------------------------------------- Register for a callback function that will be called when data is received
  Serial.println();
  Serial.println("Register for a callback function that will be called when data is received");
  esp_now_register_recv_cb(OnDataRecv);
  // ----------------------------------------

  //========================================================FastLED
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  etatLED_1 = digitalRead(LED_1);  // On mémorise l'état du bouton



  if (etatLED_1 == LOW)  // teste si le bouton a un niveau logique BAS
  {
    fill_solid( leds, NUM_LEDS, CRGB::Black); FastLED.show();

  } else  // teste si le bouton a un niveau logique différent de BAS (donc HAUT)
  {
    for (int i = 0; i < 6; i++) {  // répéter le programme 6 fois

      fill_solid( leds, NUM_LEDS, CRGB::White); FastLED.show(); delay(450);

      fill_solid( leds, NUM_LEDS, CRGB::Black); FastLED.show(); delay(1800);
    }

    fill_solid( leds, NUM_LEDS, CRGB::Black); FastLED.show(); delay(600);

    fill_solid( leds, NUM_LEDS, CRGB::White); FastLED.show(); delay(1800);

    fill_solid( leds, NUM_LEDS, CRGB::Black); FastLED.show(); delay(450);

    for (int i = 0; i <= 179; i++) { leds[i] = CRGB::Blue;
      FastLED.show();
      delay(32);
    }
    delay(4000);

    fill_solid( leds, NUM_LEDS, CRGB::White); FastLED.show(); delay(2000);
      
    
    for (int i = 0; i < 3000; i++) {
      FastLED.show();
      fadeToBlackBy(leds, NUM_LEDS, 30);  //20 correspond à la trainé
      uint8_t dothue = 0;
      for (int i = 0; i < 8; i++) {
        leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255);
        dothue += 32;
      }
    }
    for (int i = 0; i < 3000; i++) {
      FastLED.show();
      // insert a delay to keep the framerate modest
      FastLED.delay(1000 / FRAMES_PER_SECOND);
      // do some periodic updates
      EVERY_N_MILLISECONDS(20) {
        gHue++;
      }  // slowly cycle the "base color" through the rainbow
      // random colored speckles that blink in and fade smoothly
      fadeToBlackBy(leds, NUM_LEDS, 10);
      int pos = random16(NUM_LEDS);
      leds[pos] += CHSV(gHue + random8(64), 200, 255);
    }
  }
}

Maintenant j'ai un plus gros problème que l'interrupteur arrêt.
**J'utilise le protocole ESP-NOW pour pouvoir commander 10 EspEsclaves avec 1 Esp maitre. **

Après réception ce matin des Esp je n'arrive pas à l'est piloter ...en faites il me faut 1 interrupteur de préférence web, sinon au point où j'en suis un réel pour déclencher le programme sur les 10 Esp esclaves.
Alors là j'ai besoin de vos lumières !