【花雕动手做】有趣好玩的音乐可视化系列小项目(17)--光导纤维灯
项目程序之三:光纤音乐反应灯
- /*
- 【花雕动手做】有趣好玩的音乐可视化系列小项目(17)--光导纤维灯
- 项目程序之三:光纤音乐反应灯
- */
-
- #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();
- }
复制代码
|