-2

所以我在处理中写了一个脚本,可以将任何给定图像的每个像素的十六进制值输出到一个数组中。我试图让这个 FastLED 库读取数组,但我遇到了很多不同的错误。我尝试将 HEX 更改为使用 FF 和 0x 标头的字符串。似乎没有任何效果。现在它一直说十六进制值没有在范围内声明。如果我将十六进制更改为字符串,我会收到一个函数错误,告诉我它们不是刺痛。我束手无策。这是代码。

#include <FastLED.h>

#include <LEDMatrix.h>
#include <string.h>
// Change the next 6 defines to match your matrix type and size

#define LED_PIN        7
#define COLOR_ORDER    GRB
#define CHIPSET        WS2811

#define MATRIX_WIDTH   32  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_HEIGHT  8  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_TYPE    VERTICAL_ZIGZAG_MATRIX  // See top of LEDMatrix.h for matrix wiring types


cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;

char pixs [] = {{FFCE2131},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE1929},
{FFCE2131},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFC50821},
{FFCE1929},
{FFCE1929}};



void setup()
{
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
  FastLED.setBrightness(15);
  FastLED.clear(true);
  delay(500);
  FastLED.clear(true);
  Serial.begin(9600);

}

void loop() {



leds(0,0) = 0xCE2131;
leds(31,0) = CRGB::White;
leds(0,7) = CRGB::Green;
leds(31,7) = CRGB::Yellow;
FastLED.show();
delay(2000);
FastLED.clear(true);
delay(1000);

int i;
for ( i = 0; i < length.pixs ; i ++){
  leds(0,0) = pixs[i];
  FastLED.show();
}

}
4

1 回答 1

1

进化花了大约 40 亿年,这很好地表明通过随机突变进行编程并不是一个好主意。我没有arduino,也没有硬件设置来测试代码,你的描述不足以准确猜测你要做什么。那说:

你能指望什么

length.pixs

可能是什么意思?我认为 C++ 习惯用法会建议使用 std::array ,这将使您能够优雅地获取条目数。由于您坚持使用 C 数组,因此长度将由下式计算

sizeof(pixs)/sizeof(*pixs)

数组结构有缺陷,在您的代码中您访问的数组是一维的,您的类型也表示一维。所以应该是

unsigned long pixs [] = {0xCE2131, 0xCE1929, 0xCE1929}

而不是你的双括号列表。使用 0x 给出十六进制文字,仅此而已。0xCE1929 而不是 FFCE1929 没有意义(尽管是在您的代码中没有意义的标识符)

您的代码的以下版本至少在语法上是正确的,应该为您的进一步探索提供基础。

#include <LEDMatrix.h>
#include <string.h>

#define MATRIX_WIDTH   32  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_HEIGHT  8  // Set this negative if physical led 0 is opposite to where you want logical 0
#define MATRIX_TYPE    VERTICAL_ZIGZAG_MATRIX  // See top of LEDMatrix.h for matrix wiring types


cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;

unsigned long pixs [] = {0xCE2131,
    0xCE1929,0xCE1929,0xCE1929,0xCE1929,
    0xCE1929,0xCE1929,0xCE2131,0xC50821,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xC50821,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929,
    0xC50821,0xC50821,0xC50821,0xC50821,
    0xC50821,0xC50821,0xCE1929,0xCE1929};



void setup()
{
    FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
    FastLED.setBrightness(15);
    FastLED.clear(true);
    delay(500);
    FastLED.clear(true);
    Serial.begin(9600);
}

void loop() {
    leds(0,0) = 0xCE2131;
    leds(31,0) = CRGB::White;
    leds(0,7) = CRGB::Green;
    leds(31,7) = CRGB::Yellow;
    FastLED.show();
    delay(2000);
    FastLED.clear(true);
    delay(1000);

    for (int i = 0; i < sizeof(pixs)/sizeof(*pixs) ; i ++){
        leds(0,0) = pixs[i];
        FastLED.show();
    }

}
于 2017-08-25T00:31:16.503 回答