【花雕动手做】有趣好玩的音乐可视化系列项目(28)--LED乒乓球灯
项目程序之二:NeoPixel 环形灯测试程序
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT A0
-
-
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
- #endif
-
-
-
- #define LED_PIN 6
-
-
- #define LED_COUNT 101
-
-
- Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
-
-
-
-
-
-
-
-
-
-
-
-
- void setup() {
-
-
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
- clock_prescale_set(clock_div_1);
- #endif
-
-
- strip.begin();
- strip.show();
- strip.setBrightness(150);
- }
-
-
-
-
- void loop() {
-
- colorWipe(strip.Color(255, 0, 0), 250);
- colorWipe(strip.Color( 0, 255, 0), 250);
- colorWipe(strip.Color( 0, 0, 255), 250);
-
-
- theaterChase(strip.Color(127, 127, 127), 250);
- theaterChase(strip.Color(127, 0, 0), 250);
- theaterChase(strip.Color( 0, 0, 127), 250);
-
- rainbow(10);
- theaterChaseRainbow(50);
- }
-
-
-
-
-
-
-
-
-
- void colorWipe(uint32_t color, int wait) {
- for (int i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, color);
- strip.show();
- delay(30);
- }
- }
-
-
-
-
- void theaterChase(uint32_t color, int wait) {
- for (int a = 0; a < 20; a++) {
- for (int b = 0; b < 3; b++) {
- strip.clear();
-
- for (int c = b; c < strip.numPixels(); c += 3) {
- strip.setPixelColor(c, color);
- }
- strip.show();
- delay(30);
- }
- }
- }
-
-
- void rainbow(int wait) {
-
-
-
-
- for (long firstPixelHue = 0; firstPixelHue < 2 * 65536; firstPixelHue += 256) {
- for (int i = 0; i < strip.numPixels(); i++) {
-
-
-
- int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
-
-
-
-
-
- strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
- }
- strip.show();
- delay(2);
- }
- }
-
-
- void theaterChaseRainbow(int wait) {
- int firstPixelHue = 0;
- for (int a = 0; a < 30; a++) {
- for (int b = 0; b < 3; b++) {
- strip.clear();
-
- for (int c = b; c < strip.numPixels(); c += 3) {
-
-
-
- int hue = firstPixelHue + c * 65536L / strip.numPixels();
- uint32_t color = strip.gamma32(strip.ColorHSV(hue));
- strip.setPixelColor(c, color);
- }
- strip.show();
- delay(50);
- firstPixelHue += 65536 / 90;
- }
- }
- }
|