单片机教程网

电脑版
提示:原网页已由神马搜索转码, 内容由www.51hei.com提供.
查看:2236|回复:0
打印上一主题下一主题

arduino的关于音律灯的源代码

[复制链接]
跳转到指定楼层
楼主
ID:996739发表于 2021-12-25 12:21|只看该作者回帖奖励
#include< FastLED.h>

int sound_value;  
#define NUM_LEDS 30  //灯珠数
#define LED_PIN 2  
#define ANALOG_READ 35

CRGB leds[NUM_LEDS];

void setup(){
   Serial.begin(9600);
   FastLED.setBrightness(30);
   FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {

sound_value = analogRead(ANALOG_READ);      
if(sound_value > 2000&& sound_value< 2200){
   for (int i = 0; i< = 10; i++)
   leds[i] = CRGB(255, 0, 0);  //五分之一的灯珠绿光
   for (int j = 11; j< = NUM_LEDS; j++)
   leds[j] = CRGB(0, 0, 0);
   FastLED.show();
   delay(15);
}

if(sound_value > 2400&& sound_value< 2600){
   for (int i = 0; i< = 18; i++)
   leds[i] = CRGB(0, 0, 255);  //五分之二的灯珠蓝光
   for (int j = 19; j< = NUM_LEDS; j++)
   leds[j] = CRGB(0, 0, 0);
   FastLED.show();
   delay(15);
}

if(sound_value > 2800&& sound_value< 3000){
   for (int i = 0; i< = 26; i++)
   leds[i] = CRGB(0, 125, 125);  //五分之三的灯珠紫光
   for (int j = 27; j< = NUM_LEDS; j++)
   leds[j] = CRGB(0, 0, 0);
   FastLED.show();
   delay(15);
}

if(sound_value > 3200&& sound_value< 3400){
   for (int i = 0; i< = 34; i++)
   leds[i] = CRGB(125, 125, 0);  //五分之四的灯珠黄光
   for (int j = 35; j< = NUM_LEDS; j++)
   leds[j] = CRGB(0, 0, 0);
   FastLED.show();
   delay(15);
}

if(sound_value > 3500){
   for (int i = 0; i< = NUM_LEDS; i++)
   leds[i] = CRGB(0, 255, 0);  //全部红光
   FastLED.show();
   delay(5);
}
}


手机版|小黑屋|51黑电子论坛|51黑电子论坛6群QQ管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网