【花雕动手做】有趣好玩的音乐可视化系列小项目(19)--通体光纤灯
项目程序之四:通体光纤音乐反应灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(19)--通体光纤灯
项目程序之四:通体光纤音乐反应灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7
*/
#define FASTLED_INTERRUPT_RETRY_COUNT 0
//#define FASTLED_ESP8266_RAW_PIN_ORDER
#include <FastLED.h>
#define NUM_LEDS 4
CRGB leds[NUM_LEDS];
const int ledPin = 6;
int sensorPin = 7;
boolean val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
FastLED.addLeds<WS2812B, ledPin, RGB>(leds, NUM_LEDS);
}
void loop () {
val = digitalRead(sensorPin);
Serial.println (val);
if (val == HIGH) {
leds[0] = CRGB(250, 0, 0);
FastLED.show();
delay(8);
leds[1] = CRGB(0, 250, 0);
FastLED.show();
delay(8);
leds[2] = CRGB(0, 0, 250);
FastLED.show();
delay(8);
leds[3] = CRGB(250, 0, 250);
FastLED.show();
delay(8);
}
else {
leds[4] = CRGB(250, 20, 20);
FastLED.show();
}
FastLED.clear();
}
|