1 #include "pitches.h" 2 #include "FastLED.h" 3 int Renpin = 2; 4 int LEDpin = 13; 5 int Micpin = 0; 6 int Buzpin = 5; 7 #define NUM_LEDS 8 // LED灯珠数量 8 #define DATA_PIN 4 // Arduino输出控制信号引脚 9 #define LED_TYPE WS2812 // LED灯带型号 10 #define COLOR_ORDER GRB // RGB灯珠中红色、绿色、蓝色LED的排列顺序 11 uint8_t max_bright = 128; // LED亮度控制变量,可使用数值为 0 ~ 255, 数值越大则光带亮度越高 12 CRGB leds[NUM_LEDS]; 13 int Micval = 0; 14 int Renval = 0; 15 long frequency = 2048; // 16 void setup() { 17 pinMode(Buzpin,OUTPUT); 18 pinMode(Renpin,INPUT); 19 Serial.begin(115200); //set up serial library baud rate to 9600 20 LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // 初始化光带 21 FastLED.setBrightness(max_bright); 22 } 23 24 void loop() { 25 Renval = digitalRead(Renpin); // 26 if (Renval >= 1){ 27 Micval = analogRead(Micpin); // 28 Serial.println(Renval); // 29 Serial.println(Micval); // 30 tone(Buzpin,frequency); 31 fill_solid(leds,8,CRGB::Red); // 设置光带中第一个灯珠颜色为红色,leds[0]为第一个灯珠,leds[1]为第二个灯珠 32 FastLED.show(); // 更新LED色彩 33 delay(300); 34 fill_solid(leds,8,CRGB::Black); 35 FastLED.show(); 36 noTone(Buzpin); 37 } 38 }