eagler8 发表于 2020-3-1 10:14:24

eagler8 发表于 2020-3-1 10:37:29

程序之四:黑客帝国绿色流水灯

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装FastLED库,工具—管理库—搜索FastLED—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之四:黑客帝国绿色流水灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
*/

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define MAX_LED 64

#define ADD true
#define SUB false

int val = 0;
boolean stat = ADD;

Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );

void setup()
{
strip.begin();
strip.show();
}

void loop()
{
uint8_t i, a = 0;
uint32_t color = strip.Color(190, 50, 0);
while (a < 65)
{
    for (i = 0; i < 64; i++)
    {
      if (i == a) strip.setPixelColor(i, color);
      else strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(25);
    a++;
}
}

eagler8 发表于 2020-3-1 10:48:16

程序之五:RGB传输测试满屏变幻彩灯

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之五:RGB传输测试满屏变幻彩灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
*/


#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?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN   6

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

// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 50

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + 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_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 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() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.

strip.begin();         // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show();            // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

void loop() {
// Fill along the length of the strip in various colors...
colorWipe(strip.Color(255,   0,   0)   , 50); // Red
colorWipe(strip.Color(0, 255,   0)   , 50); // Green
colorWipe(strip.Color(0,   0, 255)   , 50); // Blue
colorWipe(strip.Color(0,   0,   0, 255), 50); // True white (not RGB white)

whiteOverRainbow(75, 5);

pulseWhite(5);

rainbowFade2White(3, 3, 1);
}

// 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
}
}

void whiteOverRainbow(int whiteSpeed, int whiteLength) {

if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;

int      head          = whiteLength - 1;
int      tail          = 0;
int      loops         = 3;
int      loopNum       = 0;
uint32_t lastTime      = millis();
uint32_t firstPixelHue = 0;

for(;;) { // Repeat forever (or until a 'break' or 'return')
    for(int i=0; i<strip.numPixels(); i++) {// For each pixel in strip...
      if(((i >= tail) && (i <= head)) ||      //If between head & tail...
         ((tail > head) && ((i >= tail) || (i <= head)))) {
      strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
      } else {                                             // else set rainbow
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      }
    }

    strip.show(); // Update strip with new contents
    // There's no delay here, it just runs full-tilt until the timer and
    // counter combination below runs out.

    firstPixelHue += 40; // Advance just a little along the color wheel

    if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
      if(++head >= strip.numPixels()) {      // Advance head, wrap around
      head = 0;
      if(++loopNum >= loops) return;
      }
      if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
      tail = 0;
      }
      lastTime = millis();                   // Save time of last movement
    }
}
}

void pulseWhite(uint8_t wait) {
for(int j=0; j<256; j++) { // Ramp up from 0 to 255
    // Fill entire strip with white at gamma-corrected brightness level 'j':
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(wait);
}

for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
    strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
    strip.show();
    delay(wait);
}
}

void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
int fadeVal=0, fadeMax=100;

// Hue of first pixel runs 'rainbowLoops' 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 rainbowLoops*65536, using steps of 256 so we
// advance around the wheel at a decent clip.
for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
    firstPixelHue += 256) {

    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the three-argument variant, though the
      // second value (saturation) is a constant 255.
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
      255 * fadeVal / fadeMax)));
    }

    strip.show();
    delay(wait);

    if(firstPixelHue < 65536) {                              // First loop,
      if(fadeVal < fadeMax) fadeVal++;                     // fade in
    } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
      if(fadeVal > 0) fadeVal--;                           // fade out
    } else {
      fadeVal = fadeMax; // Interim loop, make sure fade is at max
    }
}

for(int k=0; k<whiteLoops; k++) {
    for(int j=0; j<256; j++) { // Ramp up 0 to 255
      // Fill entire strip with white at gamma-corrected brightness level 'j':
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
    delay(1000); // Pause 1 second
    for(int j=255; j>=0; j--) { // Ramp down 255 to 0
      strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
      strip.show();
    }
}

delay(500); // Pause 1/2 second
}

eagler8 发表于 2020-3-1 11:21:30


程序之五:RGB传输测试满屏变幻彩灯 视频(52秒)

链接:https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html


https://v.youku.com/v_show/id_XNDU2ODQ2MDI0NA==.html

eagler8 发表于 2020-3-1 11:32:00

【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之六:复合流水彩虹灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之六:复合流水彩虹灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
*/

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define BRIGHTNESS 64

Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show();
}

void loop() {
colorWipe(strip.Color(150, 0, 0), 50); // Red
colorWipe(strip.Color(0, 150, 0), 50); // Green
colorWipe(strip.Color(0, 0, 150), 50); // Blue
colorWipe(strip.Color(150, 150, 150), 50); // BlueWite
rainbowCycle(1);

}

void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255 ));
    }
    strip.show();
    delay(wait);
}
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
}
}

uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

eagler8 发表于 2020-3-1 11:58:13

程序之七:复合飘逸彩虹满屏灯

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之七:复合飘逸彩虹满屏灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
*/

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

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code

strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
// Some example procedures showing how to display to the pixels:
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
// Send a theater pixel chase in...
theaterChase(strip.Color(127, 127, 127), 50); // White
theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color(0, 0, 127), 50); // Blue

rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) {//do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
      strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
      strip.setPixelColor(i+q, 0);      //turn every third pixel off
      }
    }
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) {   // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
      strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
      strip.setPixelColor(i+q, 0);      //turn every third pixel off
      }
    }
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

eagler8 发表于 2020-3-1 12:31:05

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之八:复合彩虹滚动流水灯
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
*/

#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?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

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

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, 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_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 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)


// setup() function -- runs once at startup --------------------------------

void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.

strip.begin();         // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show();            // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}


// loop() function -- runs repeatedly as long as board is on ---------------

void loop() {
// Fill along the length of the strip in various colors...
colorWipe(strip.Color(255,   0,   0), 50); // Red
colorWipe(strip.Color(0, 255,   0), 50); // Green
colorWipe(strip.Color(0,   0, 255), 50); // Blue

// 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

rainbow(10);             // Flowing rainbow cycle along the whole strip
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
}


// 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
    }
}
}

// 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 outer loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    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
    }
}
}

eagler8 发表于 2020-3-1 12:39:13


程序之九:按键控制进入下段彩灯程序
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
ws——D2

/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验一百四十六:64位 WS2812B8*8 xRGB 5050 LED模块 ws2812s像素点阵屏
安装NeoPixel库,工具—管理库—搜索NeoPixel—安装
安装Adafruit_NeoPixel库,
下载https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation

程序之九:按键控制进入下段彩灯程序
实验接线
Module    UNO
VCC —— 3.3V
GND —— GND
DI——D6
ws——D2
*/

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define BUTTON_PIN   2

#define PIXEL_PIN    7// Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 64 // Number of NeoPixels

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, 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_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 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)

boolean oldState = HIGH;
int   mode   = 0;    // Currently-active animation mode, 0-9

void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show();// Initialize all pixels to 'off'
}

void loop() {
// Get current button state.
boolean newState = digitalRead(BUTTON_PIN);

// Check if state changed from high to low (button press).
if ((newState == LOW) && (oldState == HIGH)) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {   // Yes, still low
      if (++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
      switch (mode) {          // Start the new animation...
      case 0:
          colorWipe(strip.Color(0,   0,   0), 50);    // Black/off
          break;
      case 1:
          colorWipe(strip.Color(255,   0,   0), 50);    // Red
          break;
      case 2:
          colorWipe(strip.Color(0, 255,   0), 50);    // Green
          break;
      case 3:
          colorWipe(strip.Color(0,   0, 255), 50);    // Blue
          break;
      case 4:
          theaterChase(strip.Color(127, 127, 127), 50); // White
          break;
      case 5:
          theaterChase(strip.Color(127,   0,   0), 50); // Red
          break;
      case 6:
          theaterChase(strip.Color(0,   0, 127), 50); // Blue
          break;
      case 7:
          rainbow(10);
          break;
      case 8:
          theaterChaseRainbow(50);
          break;
      }
    }
}

// Set the last-read button state to the old state.
oldState = newState;
}

// 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
    }
}
}

// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
// Hue of first pixel runs 3 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 3*65536. Adding 256 to firstPixelHue each time
// means we'll make 3*65536/256 = 768 passes through this outer loop:
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
    for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    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
    }
}
}

eagler8 发表于 2020-3-1 13:09:39

实验仿真编程(linkboy3.6)之一

eagler8 发表于 2020-3-1 13:22:12

实验仿真编程(linkboy3.6)之二

eagler8 发表于 2020-3-1 14:21:25

实验仿真编程(linkboy3.6)之三

eagler8 发表于 2020-3-2 18:12:52


程序之四:黑客帝国绿色流水灯








eagler8 发表于 2020-3-4 16:35:57

视频——程序之六:复合流水彩虹灯

https://v.youku.com/v_show/id_XNDU2ODUwMTE2NA==.html

https://v.youku.com/v_show/id_XNDU2ODUwMTE2NA==.html
页: 1 [2]
查看完整版本: 【Arduino】168种传感器模块系列实验(147)---64位WS2812点阵屏