Arduino点亮LED灯带
生活随笔
收集整理的這篇文章主要介紹了
Arduino点亮LED灯带
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
物品清單
| 開發(fā)板 | Arduino | 1 |
| 杜邦線 | 公公 母母 公母 | 若干 |
| 燈帶 | 30/60珠 | 1 |
| 電源 | 5V 2000A左右 | 1 |
| 面包板 | 1 |
相關代碼
相關庫:FastLED
示例代碼
#include <FastLED.h>FASTLED_USING_NAMESPACE// FastLED "100-lines-of-code" demo reel, showing just a few // of the kinds of animation patterns you can quickly and easily // compose using FastLED. // // This example also shows one easy way to define multiple // animations patterns and have them automatically rotate. // // -Mark Kriegsman, December 2014#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif#define DATA_PIN 9 //#define CLK_PIN 4 #define LED_TYPE WS2812 #define COLOR_ORDER GRB #define NUM_LEDS 60 //燈珠數(shù)量 CRGB leds[NUM_LEDS];#define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120void setup() {delay(3000); // 3 second delay for recovery// tell FastLED about the LED strip configurationFastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);// set master brightness controlFastLED.setBrightness(BRIGHTNESS); }// List of patterns to cycle through. Each is defined as a separate function below. typedef void (*SimplePatternList[])(); SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current uint8_t gHue = 0; // rotating "base color" used by many of the patternsvoid loop() {// Call the current pattern function once, updating the 'leds' arraygPatterns[gCurrentPatternNumber]();// send the 'leds' array out to the actual LED stripFastLED.show(); // insert a delay to keep the framerate modestFastLED.delay(1000/FRAMES_PER_SECOND); // do some periodic updatesEVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbowEVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically }#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))void nextPattern() {// add one to the current pattern number, and wrap around at the endgCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); }void rainbow() {// FastLED's built-in rainbow generatorfill_rainbow( leds, NUM_LEDS, gHue, 7); }void rainbowWithGlitter() {// built-in FastLED rainbow, plus some random sparkly glitterrainbow();addGlitter(80); }void addGlitter( fract8 chanceOfGlitter) {if( random8() < chanceOfGlitter) {leds[ random16(NUM_LEDS) ] += CRGB::White;} }void confetti() {// random colored speckles that blink in and fade smoothlyfadeToBlackBy( leds, NUM_LEDS, 10);int pos = random16(NUM_LEDS);leds[pos] += CHSV( gHue + random8(64), 200, 255); }void sinelon() {// a colored dot sweeping back and forth, with fading trailsfadeToBlackBy( leds, NUM_LEDS, 20);int pos = beatsin16( 13, 0, NUM_LEDS-1 );leds[pos] += CHSV( gHue, 255, 192); }void bpm() {// colored stripes pulsing at a defined Beats-Per-Minute (BPM)uint8_t BeatsPerMinute = 62;CRGBPalette16 palette = PartyColors_p;uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);for( int i = 0; i < NUM_LEDS; i++) { //9948leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));} }void juggle() {// eight colored dots, weaving in and out of sync with each otherfadeToBlackBy( leds, NUM_LEDS, 20);byte dothue = 0;for( int i = 0; i < 8; i++) {leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);dothue += 32;} }需要修改地方
#define DATA_PIN 9 //信號引腳 #define LED_TYPE WS2812 //燈帶類型 #define COLOR_ORDER GRB //燈帶燈排列順序 #define NUM_LEDS 60 //燈珠數(shù)量上傳代碼
編譯上傳,看看效果吧
總結
以上是生活随笔為你收集整理的Arduino点亮LED灯带的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql ip 查询工具_IP地址查询
- 下一篇: BZOJ4833 [Lydsy1704月