【花雕动手做】有趣好玩的音乐可视化系列小项目(14)---水杯水瓶灯
项目程序之二:多彩动态音乐反应灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(14)---水杯水瓶灯
项目程序之二:多彩动态音乐反应灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
*/
#define FASTLED_INTERRUPT_RETRY_COUNT 0
#include <FastLED.h>
#define NUM_LEDS 12
CRGB leds[NUM_LEDS];
const int ledPin = 6;
int sensorPin = 7;
boolean val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
FastLED.setBrightness(60);
FastLED.addLeds<WS2812B, ledPin, RGB>(leds, NUM_LEDS);
}
void loop () {
val = digitalRead(sensorPin);
Serial.println (val);
if (val == HIGH) {
leds[0] = CRGB(180, 0, 0);
FastLED.show();
delay(3);
leds[1] = CRGB(0, 180, 0);
FastLED.show();
delay(3);
leds[2] = CRGB(0, 0, 240);
FastLED.show();
delay(3);
leds[3] = CRGB(150, 0, 240);
FastLED.show();
delay(5);
leds[4] = CRGB(180, 200, 20);
FastLED.show();
delay(5);
leds[5] = CRGB(85, 60, 180);
FastLED.show();
delay(10);
leds[6] = CRGB(50, 220, 20);
FastLED.show();
delay(5);
FastLED.show();
leds[7] = CRGB(0, 0, 250);
FastLED.show();
delay(5);
FastLED.show();
leds[8] = CRGB(240, 0, 0);
FastLED.show();
delay(10);
leds[9] = CRGB(0, 250, 0);
FastLED.show();
delay(10);
leds[10] = CRGB(0, 0, 255);
FastLED.show();
delay(10);
leds[11] = CRGB(220, 200, 20);
FastLED.show();
delay(10);
}
else {
leds[12] = CRGB(150, 0, 255);
FastLED.show();
}
FastLED.clear();
}
|