使用Arduino在LED矩阵上显示HEX值数组

时间:2017-08-24 23:03:14

标签: c++ c arrays arduino-uno led

所以我在Processing中编写了一个脚本,可以将任何给定图像的每个像素的HEX值输出到一个数组中。我试图让这个FastLED库读取数组,我得到了很多不同的错误。我尝试将HEX更改为我使用FF和0x标头的字符串。似乎没有任何作用。现在它一直说在示波器中没有声明Hex值。如果我将hexes更改为字符串,我会得到一个函数错误,告诉我它们不是蜇。我在智慧结束。这是代码。

#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();
}

}

1 个答案:

答案 0 :(得分:1)

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

你期待什么

length.pixs

可能意味着什么? C ++习惯用法建议使用std :: array我认为,这样可以优雅地获得条目数。由于您坚持使用C数组,因此长度将通过

计算
sizeof(pixs)/sizeof(*pixs)

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

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();
    }

}