用固定的2812替换octoWS2811以进行流传输

时间:2019-11-05 19:57:05

标签: arduino fastled neopixel

您好,arduino程序员,我目前正在研究LED矩阵,其中我在驱动30x7(210led WS2812)矩阵。我为这项工作使用了arduino nano。

我在互联网上找到了这部分代码,但这是使用octoWS2811库的,我希望在没有ws2811 octo库的情况下就可以使用它,因为这仅适用于teensys。

原始代码如下:

#include <OctoWS2811.h>

#include<OctoWS2811.h>
#include<FastLED.h>

// ------------ Change these as neccesary -----------//
#define NUM_LEDS_PER_STRIP 400
#define NUM_STRIPS 8

CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
const int numOfBytes = NUM_LEDS_PER_STRIP * NUM_STRIPS * 3;
const int numLeds = NUM_LEDS_PER_STRIP * NUM_STRIPS;
 char inputBuffer[numOfBytes];

// ------------------- Setup -------------------- //
 void setup() {
  LEDS.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIP);
  LEDS.setBrightness(255);
  delay(500);
  Serial.begin(115200);
  Serial.setTimeout(500);
  LEDS.show();
}

// ------------------- Main Loop -------------------- //
void loop() {
if(Serial.available() > 0) {
  Serial.readBytes(inputBuffer, numOfBytes);
}
  for (int j = 0; j < numLeds; j++) {
    leds[j] = CRGB(inputBuffer[(j*3)],inputBuffer[(j*3)+1],inputBuffer[(j*3)+2]);
  }
  LEDS.show();
}

并且我希望它可以像这样工作:

#include<FastLED.h>

// ------------ Change these as neccesary -----------//
#define NUM_LEDS_PER_STRIP 400
#define NUM_STRIPS 8

CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
const int numOfBytes = NUM_LEDS_PER_STRIP * NUM_STRIPS * 3;
const int numLeds = NUM_LEDS_PER_STRIP * NUM_STRIPS;
 char inputBuffer[numOfBytes];

// ------------------- Setup -------------------- //
 void setup() {
 FastLED.addLeds<NEOPIXEL, 3>(leds, 0, Num_Leds);
 FastLED.addLeds<NEOPIXEL, 4>(leds, Num_Leds, Num_Leds);
 FastLED.addLeds<NEOPIXEL, 5>(leds, 2 * Num_Leds, Num_Leds);
  FastLED.addLeds<NEOPIXEL, 6>(leds, 3 * Num_Leds, Num_Leds); -------to let fastled know it should be seen as a single led-strip
  FastLED.addLeds<NEOPIXEL, 7>(leds, 4 * Num_Leds, Num_Leds);
  FastLED.addLeds<NEOPIXEL, 8>(leds, 5 * Num_Leds, Num_Leds);
  FastLED.setBrightness(255);
  delay(500);
  Serial.begin(115200);
  Serial.setTimeout(500);
  FastLED.show();
}

// ------------------- Main Loop -------------------- //
void loop() {
if(Serial.available() > 0) {
  Serial.readBytes(inputBuffer, numOfBytes);
}
  for (int j = 0; j < numLeds; j++) {
    leds[j] = CRGB(inputBuffer[(j*3)],inputBuffer[(j*3)+1],inputBuffer[(j*3)+2]);
  }
  FastLED.show();
}

对此有何建议?它应该是一段简单的流式代码,但我无法弄清楚如何使用固定库和NEOPIXEL / ws2812 leds进行编译。

0 个答案:

没有答案