arduino之灯带编程
生活随笔
收集整理的這篇文章主要介紹了
arduino之灯带编程
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
arduino編程LED燈帶示例
燈帶使用的是WS2812,FastLED庫是第三方庫,網(wǎng)上有下載和導(dǎo)入教程,實(shí)現(xiàn)了3種效果,流水,靜態(tài)彩虹,閃爍。
#include "FastLED.h" // FastLED庫#define NUM_LEDS 60 // LED燈珠數(shù)量 #define DATA_PIN 2 // Arduino輸出控制信號引腳 #define LED_TYPE WS2812 // LED燈帶型號 #define COLOR_ORDER GRB // RGB燈珠中紅色、綠色、藍(lán)色LED的排列順序uint8_t max_bright = 128; // LED亮度控制變量,可使用數(shù)值為 0 ~ 255, 數(shù)值越大則光帶亮度越高CRGB leds[NUM_LEDS]; // 建立光帶ledsvoid led_rainbow_loop(void){FastLED.clear();FastLED.show();delay(500);fill_solid(leds, 60, CRGB::Red);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Orange);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Yellow);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Green);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Cyan);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Blue);FastLED.show();delay(1000); // 等待1秒fill_solid(leds, 60, CRGB::Purple);FastLED.show();delay(1000); // 等待1秒 }void led_rainbow_flowing(void) {FastLED.clear();FastLED.show();delay(500);int i = 0,loop_count = 0;if(NUM_LEDS%7 == 0){loop_count = NUM_LEDS/7;}else{loop_count = NUM_LEDS/7+1;}for(i=0; i<loop_count; i++){leds[i*7] = CRGB::Red;FastLED.show();delay(200);if(i*7+1>=NUM_LEDS) {break;}leds[i*7+1] = CRGB::Orange;FastLED.show();delay(200);if(i*7+2>=NUM_LEDS) {break;}leds[i*7+2] = CRGB::Yellow;FastLED.show();delay(200);if(i*7+3>=NUM_LEDS) {break;}leds[i*7+3] = CRGB::Green;FastLED.show();delay(200);if(i*7+4>=NUM_LEDS) {break;}leds[i*7+4] = CRGB::Cyan;FastLED.show();delay(200);if(i*7+5>=NUM_LEDS) {break;}leds[i*7+5] = CRGB::Blue;FastLED.show();delay(200);if(i*7+6>=NUM_LEDS) {break;}leds[i*7+6] = CRGB::Purple;FastLED.show();delay(200);if(i*7+7>=NUM_LEDS) {break;}}}void led_rainbow_static(void){FastLED.clear();FastLED.show();delay(500);fill_rainbow(leds, 60, 0, 15);FastLED.show();delay(1000); }void setup() { LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // 初始化光帶 FastLED.setBrightness(max_bright); // 設(shè)置光帶亮度 }void loop() { while(1){led_rainbow_flowing();led_rainbow_static();led_rainbow_loop();} }總結(jié)
以上是生活随笔為你收集整理的arduino之灯带编程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 变电站三维激光扫描应用的介绍_吉优赛维数
- 下一篇: H5移动端下拉 - mobileSele