2017-08-24 61 views
-1

所以我在Processing中編寫了一個腳本,它可以將任何給定圖像的每個像素的HEX值輸出到數組中。我試圖讓這個FastLED庫讀取數組和我得到這麼多不同的錯誤。我試着將HEX的字符串改爲FF和0x頭的字符串。似乎沒有任何工作。現在它一直說十六進制值沒有在範圍內聲明。如果我將字符串更改爲字符串,我會收到一個函數錯誤,告訴我他們不是叮咬。我在智慧結束。這是代碼。用Arduino在LED矩陣上顯示HEX值數組

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

} 
+2

歡迎來到Stack Overflow。請儘快閱讀[關於]和[問]頁面。通過用C和C++標籤標記您的問題,您正在進入微妙的領域。選擇你想要使用的語言,並堅持使用該標籤 - C或C++,但不能同時使用。適用於一種語言的答案通常不適用於另一種語言。 –

+2

刪除C語言標籤。 C語言不支持模板,例如'cLEDMatrix leds;'。嘗試使用C語言編譯器進行編譯,該語句應該會產生一些錯誤。同樣使用範圍解析運算符'::'。 –

+1

請注意,行char'[] = {{FFCE2131},'顯示多個問題。您有一個一維數組,但雙花括號只能用於更復雜的結構(二維數組或實際的C結構)。值「FFCE2131」是一個不是十六進制數字的標識符。你需要'0xFFCE2131'來使它成爲十六進制。通常不能將4個字節的數據放入單個字節對象中。 –

回答

0

進化花了約40億年,這是一個很好的跡象表明,隨機突變編程不是一個好主意。我沒有arduino,而且我沒有硬件設置來測試代碼,並且您的描述不足以準確猜測您將要執行的操作。這就是說:

你有什麼期望

length.pixs 

可能意味着或做? C++習慣用法建議使用std :: array我想,這將使您能夠優雅地獲取條目數。因爲你堅持C數組,長度將通過

sizeof(pixs)/sizeof(*pixs) 

來計算陣列結構是有缺陷的,在您的代碼訪問陣列是一維和你的類型也表示1維的。所以它應該是

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

而不是你的雙支撐列表。 Hex文字通過使用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(); 
    } 

}