0

我需要在我的 Arduino 上为一个项目构建一个新像素显示器,使用多个新像素条。我的第一步是让这些新像素条在 Circuits.io 上工作。在circuits.io中,它们只有一个可以串在一起的。

我从第一个新像素开始,它工作得很好。现在,在添加了 5 组之后,第一个不起作用,但其余的都可以!

这是草图:https ://circuits.io/circuits/5073229-v2g-display

这是我的代码(也在草图中):

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define NUMNUCLEARPIXELS 3
#define NUMWINDSOLARPIXELS 3
#define NUMSUBSTATIONPIXELS 3
#define NUMFACTORYPIXELS 3
#define NUMEVPIXELS 3
#define NUMHOMEPIXELS 3


Adafruit_NeoPixel nuclearpixels = Adafruit_NeoPixel(NUMNUCLEARPIXELS, 3 /*pin*/, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel windsolarpixels = Adafruit_NeoPixel(NUMWINDSOLARPIXELS, 5 /*pin*/, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel substationpixels = Adafruit_NeoPixel(NUMSUBSTATIONPIXELS, 6 /*pin*/, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel factorypixels = Adafruit_NeoPixel(NUMFACTORYPIXELS, 10 /*pin*/, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel evpixels = Adafruit_NeoPixel(NUMEVPIXELS, 11 /*pin*/, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel homepixels = Adafruit_NeoPixel(NUMHOMEPIXELS, 9 /*pin*/, NEO_GRB + NEO_KHZ800);


int delayval = 0; // delay for half a second

int windsolarbutton = 8;
int factorybutton = 2;
int evbutton = 4;
int homebutton = 7;

// the setup routine runs once when you press reset:
void setup() {
  // initialize digital pins as input or output

  pinMode(windsolarbutton, INPUT);
  pinMode(factorybutton, INPUT);
  pinMode(evbutton, INPUT);
  pinMode(homebutton, INPUT);

  nuclearpixels.begin(); // This initializes the NeoPixel library.
  windsolarpixels.begin();
  substationpixels.begin();
  factorypixels.begin();
  evpixels.begin();
  homepixels.begin();

}

// the loop routine runs over and over again forever:
void loop() {

 // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

     for(int i=0;i<NUMNUCLEARPIXELS;i++){
     // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    nuclearpixels.setPixelColor(i, nuclearpixels.Color(0,150,0)); // Moderately bright green color.\
    nuclearpixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
     for(int i=0;i<NUMWINDSOLARPIXELS;i++){
    windsolarpixels.setPixelColor(i, windsolarpixels.Color(0,150,0));
    windsolarpixels.show();
    delay(delayval); // Delay for a period of time (in milliseconds). 
  }
   for(int i=0;i<NUMSUBSTATIONPIXELS;i++){
    substationpixels.setPixelColor(i, substationpixels.Color(0,150,0));
    substationpixels.show();
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
   for(int i=0;i<NUMFACTORYPIXELS;i++){
    factorypixels.setPixelColor(i, factorypixels.Color(0,150,0));
    factorypixels.show();
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
   for(int i=0;i<NUMEVPIXELS;i++){
    evpixels.setPixelColor(i, evpixels.Color(0,150,0));
    evpixels.show();
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
   for(int i=0;i<NUMHOMEPIXELS;i++){
    homepixels.setPixelColor(i, homepixels.Color(0,150,0));
    homepixels.show();
    delay(delayval); // Delay for a period of time (in milliseconds).
  }

}

谢谢,感谢您的帮助!

4

0 回答 0