IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Comment utiliser 2 bandes LED couleur ?


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé

    Profil pro
    Inscrit en
    Août 2008
    Messages
    1 222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 1 222
    Par défaut Comment utiliser 2 bandes LED couleur ?
    Bonjour j'ai une bande 2 bande led à utiliser , j'ai en une qui fonctionne le début de mon code est ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    #include <Adafruit_NeoPixel.h>
     
    #ifdef __AVR__
     #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
    #endif
     
    // Which pin on the Arduino is connected to the NeoPixels?
    #define PIN        5// On Trinket or Gemma, suggest changing this to 1
    #define PIN2        4// On Trinket or Gemma, suggest changing this to 1
    // How many NeoPixels are attached to the Arduino?
    #define NUMPIXELS 16 // Popular NeoPixel ring size
     
    // When setting up the NeoPixel library, we tell it how many pixels,
    // and which pin to use to send signals. Note that for older NeoPixel
    // strips you might need to change the third parameter -- see the
    // strandtest example for more information on possible values.
    Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    par contre comment je fais si je souhaite ajouter une autre bande led ? le premier est défini par la PIN:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #define PIN        5// On Trinket or Gemma, suggest changing this to 1
    si je fait ceci cela fonctionne pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel pixels(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
    merci de votre réponse

  2. #2
    Membre Expert
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 019
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 019
    Par défaut
    Bonjour keokaz

    Il y a 2 solutions:
    En les nommant différemment
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Adafruit_NeoPixel pixelsA(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel pixelsB(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
    Ou en les soudant bout à bout en respectant le sens et en déclarant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Adafruit_NeoPixel pixels(NUMPIXELS *2, PIN, NEO_GRB + NEO_KHZ800);
    La 2ème méthode est, à mon avis, plus aisée à gérer.

    Cordialement
    jpbbricole

  3. #3
    Membre éprouvé

    Profil pro
    Inscrit en
    Août 2008
    Messages
    1 222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 1 222
    Par défaut
    merci, c'est exactement ce que souhait faire ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
     
     
    #include <Adafruit_NeoPixel.h>
    #ifdef __AVR__
     #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
    #endif
     
    // Which pin on the Arduino is connected to the NeoPixels?
    #define PIN       4  // On Trinket or Gemma, suggest changing this to 1
    #define PIN2       5  // On Trinket or Gemma, suggest changing this to 1
    // How many NeoPixels are attached to the Arduino?
    #define NUMPIXELS 30 // Popular NeoPixel ring size
     
     
    Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
    #define DELAYVAL 3 // Time (in milliseconds) to pause between pixels
     
    const int Push_button_pin = 0;   
    const int Push_button_2 = 2; 
    const int led =  14;       
    int Push_button_state = 0;
    int Push_button_state2 = 0;
    void setup() {
      pinMode(Push_button_pin, INPUT);
        pinMode(Push_button_2, INPUT);
      pinMode(led, OUTPUT);
     
    #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
      clock_prescale_set(clock_div_1);
    #endif
      // END of Trinket-specific code.
     
      pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
        pixels2.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
    }
     
    void loop() {
     
     
      //generate a random number
      int randomNumber = random(1,255);
        int randomNumber1 = random(1,255);
            int randomNumber2 = random(1,255);
     
     
      Push_button_state = digitalRead(Push_button_pin);
      if (Push_button_state == LOW) {
        for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
     
          if(randomNumber2 < 100){
            randomNumber2 =0;
          }
     
          pixels.setPixelColor(i, pixels.Color(randomNumber, randomNumber2, randomNumber1));
          pixels.show();   // Send the updated pixel colors to the hardware.
          delay(100); // Pause before next pass through loop
          }
       }
     
     
     
     
      Push_button_state2 = digitalRead(Push_button_2);
      if (Push_button_state2 == LOW) {
        for(int i=0; i<NUMPIXELS; i++) { // For each pixel.
     
          if(randomNumber2 < 100){                                                                                        
            randomNumber2 =0;
          }
     
          pixels2.setPixelColor(i, pixels2.Color(randomNumber2, randomNumber, randomNumber1));
          pixels2.show();   // Send the updated pixel colors to the hardware.
          delay(100); // Pause before next pass through loop
          }
       }
     
     
       if (Push_button_state == HIGH ) {
          pixels.clear(); 
     
        for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
     
          pixels.setPixelColor(i, pixels.Color(255,0, 0));
          pixels.show();   // Send the updated pixel colors to the hardware.
          delay(DELAYVAL); // Pause before next pass through loop
          }
        }
     
     
       if (Push_button_state2 == HIGH ) {
          pixels2.clear(); 
             for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
     
          pixels2.setPixelColor(i, pixels2.Color(0, 0, 255));
          pixels2.show();   // Send the updated pixel colors to the hardware.
          delay(DELAYVAL); // Pause before next pass through loop
          }
        }
     
    }

  4. #4
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 298
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 298
    Billets dans le blog
    48
    Par défaut
    Bonsoir,

    Quand je vois ce genre de répétitions...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    ...
       if (Push_button_state == HIGH ) {
          pixels.clear(); 
     
        for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
     
          pixels.setPixelColor(i, pixels.Color(255,0, 0));
          pixels.show();   // Send the updated pixel colors to the hardware.
          delay(DELAYVAL); // Pause before next pass through loop
          }
        }
     
     
       if (Push_button_state2 == HIGH ) {
          pixels2.clear(); 
             for(int i=NUMPIXELS; i>0; i--) { // For each pixel...
     
          pixels2.setPixelColor(i, pixels2.Color(0, 0, 255));
          pixels2.show();   // Send the updated pixel colors to the hardware.
          delay(DELAYVAL); // Pause before next pass through loop
          }
        }
    ...
    Il doit y avoir moyen d'optimiser, non ?

Discussions similaires

  1. comment utiliser une couleur stockée en base?
    Par ladine35 dans le forum iReport
    Réponses: 0
    Dernier message: 10/07/2009, 12h26
  2. Réponses: 7
    Dernier message: 04/06/2006, 13h24
  3. comment utiliser actionscript ?
    Par webs dans le forum Flash
    Réponses: 3
    Dernier message: 10/02/2003, 00h11
  4. Comment utiliser OUT ?
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 20/07/2002, 10h35
  5. Réponses: 5
    Dernier message: 11/06/2002, 16h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo