将WS2812 fastLED闪烁与milis arduino

问题描述 投票:-2回答:1

我正在尝试让我的指示灯每2秒钟使用一毫秒闪烁一次。由于我正在运行其他传感器,因此无法延迟。

到目前为止,我已经知道了,但是似乎没有用

#include "FastLED.h"
#define NUM_LEDS 12 // number of LEDS in neopixel ring
#define DATA_PIN 10 // for neopixel ring
CRGB leds[NUM_LEDS];

long period = 2000;        
long currentMillis = 0;
long startMillis = 0;

void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {

 currentMillis = millis();

  if (currentMillis - startMillis >= period) {
    startMillis = currentMillis;
    leds[7]=CRGB(255,0,0);
    FastLED.show();

  }

}
arduino led fastled
1个回答
1
投票

这能让您更近一点吗?

#include "FastLED.h"
#define NUM_LEDS 12 // number of LEDS in neopixel ring
#define DATA_PIN 10 // for neopixel ring
CRGB leds[NUM_LEDS];

unsigned long period = 2000;        
unsigned long currentMillis = 0;
unsigned long startMillis = 0;
boolean ledOn = false;

void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {

 currentMillis = millis();

  if (currentMillis - startMillis >= period) {
    startMillis = currentMillis;
    ledOn = !ledOn;
    if(ledOn){
      leds[7]=CRGB(255,0,0);
    }
    else {
      leds[7]=CRGB(0,0,0);
    }
    FastLED.show();
  }

}
© www.soinside.com 2019 - 2024. All rights reserved.