#include<Adafruit_NeoPixel.h> #define PIN D7 // pin on which the NeoPixels are connected // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 8 //流水灯数量 // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); // This is the 'setup' function. It runs once, when the Arduino is powered on or reset. voidsetup() { pixels.begin(); // This initializes the NeoPixel library. } // This is the 'loop' function. It runs over and over again, as long as the Arduino has power voidloop() { rainbow(10); // 彩虹灯
}
voidrainbow(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). pixels.rainbow(firstPixelHue); // Above line is equivalent to: // strip.rainbow(firstPixelHue, 1, 255, 255, true); pixels.show(); // Update strip with new contents delay(wait); // Pause for a moment } }