利用ESP8266快速点亮APA102

前言

为了更快的点亮APA102灯带,特作此记录,以便下次使用。

前期准备

  1. ESP8266芯片
  2. APA102灯带
  3. 杜邦线
  4. 安装Arduino IDE(软件)

硬件连线

ESP8266 APA102
D3 Data
D8 Clock
Vin 5v
GND GND
ESP8266引脚图.png

软件

  1. Arduino IDE 搭建 ESP8266 开发环境
  2. 安装FastLed库(工具->管理库->搜索“FastLed”)
  3. 随便选择一个FastLed的实例代码,并且按需更改
  4. 选择正确的串口并且编译上传(我的开发板选择的是NodeMCU V1.0)
效果图.jpeg

示例代码

#include 

// How many leds in your strip?
#define NUM_LEDS 30 

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 3
#define CLOCK_PIN 8

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
    Serial.begin(57600);
    Serial.println("resetting");
    FastLED.addLeds(leds, NUM_LEDS);
    LEDS.setBrightness(84);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
    static uint8_t hue = 0;
    Serial.print("x");
    // First slide the led in one direction
    for(int i = 0; i < NUM_LEDS; i++) {
        // Set the i'th led to red 
        leds[i] = CHSV(hue++, 255, 255);
        // Show the leds
        FastLED.show(); 
        // now that we've shown the leds, reset the i'th led to black
        // leds[i] = CRGB::Black;
        fadeall();
        // Wait a little bit before we loop around and do it again
        delay(10);
    }
    Serial.print("x");

    // Now go in the other direction.  
    for(int i = (NUM_LEDS)-1; i >= 0; i--) {
        // Set the i'th led to red 
        leds[i] = CHSV(hue++, 255, 255);
        // Show the leds
        FastLED.show();
        // now that we've shown the leds, reset the i'th led to black
        // leds[i] = CRGB::Black;
        fadeall();
        // Wait a little bit before we loop around and do it again
        delay(10);
    }
}

你可能感兴趣的:(利用ESP8266快速点亮APA102)