【花雕动手做】有趣好玩的音乐可视化系列小项目(16)--热干胶棒棒灯
项目程序之三:测试麻花棒棒灯
模块接线:WS2812B接D7
MAX4466 UNO
VCC 5V
GND GND
OUT A0
-
-
-
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
-
- #define PIN 7
-
-
-
-
-
-
-
-
-
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
-
-
-
-
-
-
- void setup() {
-
- #if defined (__AVR_ATtiny85__)
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
-
-
-
- strip.begin();
- strip.show();
- }
-
- void loop() {
-
-
-
-
-
-
-
-
-
-
- rainbow(20);
-
-
- }
-
-
- 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++) {
- for(i=0; i< strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
- }
- strip.show();
- delay(wait);
- }
- }
-
-
- void theaterChase(uint32_t c, uint8_t wait) {
- for (int j=0; j<10; j++) {
- for (int q=0; q < 3; q++) {
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, c);
- }
- strip.show();
-
- delay(wait);
-
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, 0);
- }
- }
- }
- }
-
-
- void theaterChaseRainbow(uint8_t wait) {
- for (int j=0; j < 256; j++) {
- 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));
- }
- strip.show();
-
- delay(wait);
-
- for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
- strip.setPixelColor(i+q, 0);
- }
- }
- }
- }
-
-
-
- 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);
- }
|