Bandeau led sur différent pin

Bonjour j'aimerais créer un projet avec plusieurs bandeaux leds mais qui sont branchés sur des pins différent pour que je puisse demandé parfois qu'il fasse des choses différentes chacun.

Voila un aperçu du projet :

Je ne sais pas comment concaténer plusieurs pin ensemble pour ne pas devoir écrire chaque fois mes fonction en triple.

Merci d'avance

:warning:
Post mis dans la mauvaise section, on parle anglais dans les forums généraux. déplacé vers le forum francophone.

Merci de prendre en compte les recommandations listées dans Les bonnes pratiques du Forum Francophone

Bonjour gregoire-2008

Ce n'est pas nécessaire de les séparer, tout se joue sur le numéro des LED, tu définis 3 secteurs,
Secteur 1 dev 0 à 20
Secteur 2 de 21 60
Secteur 3 de 61 à 72

Ainsi tu peux facilement leur faire faire des choses séparées et tu n'utilises qu'une pin.
Je peux te faire un exemple, si tu le désires :wink:

Cordialement
jpbbricole

Quelle bibliothèque utilisez-vous ?

Voici un aperçu de mon code car je n'ai pas tout compris.

/*
*/

// Adafruit NeoPixel - Dernière version 
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define LED_PIN    3
#define LED_PIN4   5

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 10

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2( LED_COUNT , LED_PIN4 , NEO_GRB + NEO_KHZ800 );

// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)


void setup() {
  
}

void loop() {
  
  // Do a theater marquee effect in various colors...
  theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness,
  theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
  
theaterChase(strip2.Color(127, 127, 127), 50); // White, half brightness,
  theaterChase(strip2.Color(127,   0,   0), 50); // Red, half brightness
  theaterChase(strip2.Color(  0,   0, 127), 50); // Blue, half brightness
}

// Some functions of our own for creating animated effects -----------------

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
}

// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
// between frames.
void theaterChase(uint32_t color, int wait) {
  for(int a=0; a<10; a++) {  // Repeat 10 times...
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
      // 'c' counts up from 'b' to end of strip in steps of 3...
      for(int c=b; c<strip.numPixels(); c += 3) {
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show(); // Update strip with new contents
      delay(wait);  // Pause for a moment
    }
  }
}

void theaterChase(uint32_t color, int wait) {
  for(int a=0; a<10; a++) {  // Repeat 10 times...
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
      strip2.clear();         //   Set all pixels in RAM to 0 (off)
      // 'c' counts up from 'b' to end of strip in steps of 3...
      for(int c=b; c<strip.numPixels(); c += 3) {
        strip2.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip2.show(); // Update strip with new contents
      delay(wait);  // Pause for a moment
    }
  }
}

// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    // strip.rainbow() can take a single argument (first pixel hue) or
    // optionally a few extras: number of rainbow repetitions (default 1),
    // saturation and value (brightness) (both 0-255, similar to the
    // ColorHSV() function, default 255), and a true/false flag for whether
    // to apply gamma correction to provide 'truer' colors (default true).
    strip.rainbow(firstPixelHue);
    // Above line is equivalent to:
    // strip.rainbow(firstPixelHue, 1, 255, 255, true);
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}

// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  for(int a=0; a<30; a++) {  // Repeat 30 times...
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
      // 'c' counts up from 'b' to end of strip in increments of 3...
      for(int c=b; c<strip.numPixels(); c += 3) {
        // hue of pixel 'c' is offset by an amount to make one full
        // revolution of the color wheel (range 65536) along the length
        // of the strip (strip.numPixels() steps):
        int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
        uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show();                // Update strip with new contents
      delay(wait);                 // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}

Merci d'avance

J'utulise la bibliothèque :

#include <Adafruit_NeoPixel.h>

Adafruit neopixel

Vous créez trois matrices de LED, chacune avec son numéro de LED et son pin associé, par exemple pour la bibliothèque Adafruit:

 //bandeaux-1
Adafruit_NeoPixel pixels_1(NUMPIXELS_1, PIN_1, NEO_RGB + NEO_KHZ800);
 //bandeaux-2
Adafruit_NeoPixel pixels_2(NUMPIXELS_2, PIN_2, NEO_RGB + NEO_KHZ800);
 //bandeaux-3
Adafruit_NeoPixel pixels_3(NUMPIXELS_3, PIN_3, NEO_RGB + NEO_KHZ800);

Et vous utilisez déjà chacun par son nom, par exemple l'initialisation dans le "setup", avec son arrêt

 //bandeaux-1
  pixels_1.begin();
  pixels_1.clear();
  pixels_1.show();

 //bandeaux-2
  pixels_2.begin();
  pixels_2.clear();
  pixels_2.show();

//bandeaux-3
  pixels_3.begin();
  pixels_3.clear();
  pixels_3.show();

Salutations
E.Gonzalez.

Bonsoir gregoire-2008

Voilà un exemple avec 3 "bandeaux" sur le même port, le 3 (bandeauPin);

J'ai mis un maximum de remarques, ne te gêne pas à poser des questions :wink:
Le bandeau 0 a les LED de 0 à 2
Le bandeau 1 a les LED de 3 à 6
Le bandeau 2 a les LED de 7 à 9

Le programme:

#include <Adafruit_NeoPixel.h>

//------------------------------------- Bandeau
const int bandeauPin = 3;     // Où est connecté le bandeau
const int bandeauLed = 10;     // Nombre de LED sur le bandeau, comptées de 0 à bandeauLeds-1

Adafruit_NeoPixel bandeau(bandeauLed, bandeauPin, NEO_GRB + NEO_KHZ800);

//------------------------------------- Secteurs (sect)

enum {sect0, sect1, sect2};     // Enumération des secteurs

enum {sectStart, sectEnd};     // Enumération des paramètres
const int sectStartEnd[][2] =     // Contient le début et la fin du chaque secteur
{
	{0, 2},     // Limites du secteur 0
	{3, 6},     // Limites du secteur 1
	{7, bandeauLed-1}     // Limites du secteur 2
};
const int sectNombre = sizeof(sectStartEnd)/sizeof(sectStartEnd[0]);

const unsigned long sect0tempo = 1000;     // Rythme du secteur 0
unsigned long sect0millis = millis();     // Rythme du secteur 0 chrono

const unsigned long sect1tempo = 200;     // Rythme du secteur 1
unsigned long sect1millis = millis();     // Rythme du secteur 1 chrono

const unsigned long sect2tempo = 500;     // Rythme du secteur 2
unsigned long sect2millis = millis();     // Rythme du secteur 1 chrono

void setup()
{
	Serial.begin(115200);

	bandeau.begin();     // Démarrage du bandeau
	bandeau.setBrightness(30);     // Luminosité, de 0 à 255

	Serial.println("Nombre de secteurs = " + String(sectNombre));
}

void loop()
{
	if (millis() - sect0millis >= sect0tempo)     // S'il est temps de jouer le secteur 0
	{
		sect0show();
		sect0millis = millis();     // Redémarrage du chrono du secteur 0
	}

	if (millis() - sect1millis >= sect1tempo)     // S'il est temps de jouer le secteur 1
	{
		sect1show();
		sect1millis = millis();     // Redémarrage du chrono du secteur 1
	}

	if (millis() - sect2millis >= sect2tempo)     // S'il est temps de jouer le secteur 2
	{
		sect2show();
		sect2millis = millis();     // Redémarrage du chrono du secteur 1
	}

}

//
void sect0show()
{
	static boolean sectAllume = 1;     // Si les LED allumées ou pas

	//                        LED de départ                        LED de fin
	for (int l = sectStartEnd[sect0][sectStart]; l <= sectStartEnd[sect0][sectEnd]; l ++)
	{
		if (sectAllume)
		{
			bandeau.setPixelColor(l, 0, 255, 0);     // En vert
		} 
		else
		{
			bandeau.setPixelColor(l, 0, 0, 0);     // Eteint
		}
	}
	bandeau.show();
	sectAllume = !sectAllume;     // Inversion de sectAllume
}

void sect1show()
{
	static boolean sectBleu;     // Si LED allumées en bleu ou pas

	//                        LED de départ                        LED de fin
	for (int l = sectStartEnd[sect1][sectStart]; l <= sectStartEnd[sect1][sectEnd]; l ++)
	{
		if (sectBleu)
		{
			bandeau.setPixelColor(l, 0, 0, 255);     // En bleu
		}
		else
		{
			bandeau.setPixelColor(l, 255, 0, 0);     // Rouge
		}
	}
	bandeau.show();
	sectBleu = !sectBleu;     // Inversion de la couleur
}

void sect2show()
{
	static int ledAllume = sectStartEnd[sect2][sectStart];     // Quelle LED allumée
	//                        LED de départ                        LED de fin
	for (int l = sectStartEnd[sect2][sectStart]; l <= sectStartEnd[sect2][sectEnd]; l ++)
	{
		if (l == ledAllume)
		{
			bandeau.setPixelColor(l, 255, 255, 255);     // En blanc
		}
		else
		{
			bandeau.setPixelColor(l, 0, 0, 0);     // Eteint
		}
	}
	
	ledAllume ++;
	if (ledAllume > sectStartEnd[sect2][sectEnd])     // Si numéro de LED dépasse la dernière du secteur
	{
		ledAllume = sectStartEnd[sect2][sectStart];
	}

	bandeau.show();
}

Et une simulation 1 bandeau 3 secteurs

Une simulation 3 bandeaux sur 3 pin de l'Arduino

Cordialement
jpbbricole

Si tu veux pouvoir utiliser la même fonction sur plusieurs strip, il suffit de lui passer le nom du strip en argument.

Et tu appelles la fonction comme ça

theaterChase(strip, strip.Color(127, 127, 127), 50);
theaterChase(strip2, strip2.Color(127, 127, 127), 50);

Mais il faut faire attention tu as des delay() dans tes fonctions qui peuvent t'empêcher d'animer les autres strips en même temps. Il faudrait sans doute revoir un peu la logique de fonctionnement.

Un tout grand merci pour toutes vos réponses ça m'a bien aidé !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.