找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2912|回復(fù): 0
收起左側(cè)

arduino的關(guān)于音律燈的源代碼

[復(fù)制鏈接]
ID:996739 發(fā)表于 2021-12-25 12:21 | 顯示全部樓層 |閱讀模式
#include <FastLED.h>

int sound_value;  
#define NUM_LEDS 30  //燈珠數(shù)
#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);  //五分之二的燈珠藍(lán)光
   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);
}
}


相關(guān)帖子

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表