2016-04-27 75 views
1

任何人都有我的錯在從文本文件(SD)中提取數據並沿着DMX發送的問題?該代碼適用於P9813部分,DMX一般適用,但不適用於SD數據。從Arduino SD卡讀取字節到DMX照明

Pastebin Code Here

我相信我的問題是,在第68行我覺得這是讀了太多的值。 IE currentColor存儲5個值(5燈)vs 1 Hex或3xR/G/B。

可供考慮的SD值是......「727a 6276 3030 ...」。我相信這些字節應該是每個DMX通道的PWM值,不是嗎?

感謝

回答

0
currentColor = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB 

我不知道你的圖書館,但我會想到的ReadBytes()調用這樣的實際存儲你想進入leds數據,並將其返回多少字節能夠讀。

result = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB 
if (result != (NUM_LEDS*3)) 
{ 
    /* Handle the error here.. an action can be fill inn default values in leds[] if SD card is not working 
} 
/* from this point, use leds[], not currentColor */ 

修訂範例(未編譯測試,缺乏使用環境,CRGB未知的數據類型):

void sendDMX(int theStrip, CRGB *theColor) { 
    for(int z=0; z<3; z++) { 
    DmxSimple.write((theStrip + z), theColor[z]); //DMX Channel, PWM Value 
    } 
} 

void loop() 
{ 
    fxdata = SD.open("TCL_DMX.dat"); // read only 
    if (fxdata) 
    { 
     Serial.println("file open ok");  
    } 

    while (fxdata.available()) 
    { 
    fxdata.readBytes(leds, sizeof (leds)); //attempt to store SD card read data as RGB 

    Serial.println(fxdata); 

    sendDMX(1, leds); //RGB Strip #, RGB bytes from SD .dat file 
    FastLED.show(); 
    delay(500); 
    } 

    // close the file in order to prevent hanging IO or similar throughout time 
    fxdata.close(); 
} 
+0

我給的是,在未來幾天一試。 您能否詳細說明第一行的功能?我知道它是讀取字節,但「結果」會保持什麼?它是簡單地通過循環第一次通過「字節1」,第二次是「字節2」等等。或者是readBytes在「result」中存儲多個字節? 我想問的原因是DMX.write最終需要單個值0-255。 leds []變量應該保存3個字符的RGB值,可以通過leds [0] .r,leds [0] .g,leds [0] .b單獨訪問。 – joshjingles

+0

DMX應該有總共512個通道的數據。如果DMX.write採用兩個數字值,則可能會設置其中一個,所以如果要設置3個通道,請調用三次。 (在pastebin中添加dmx和sd卡頭文件,以便我可以窺視) –

+0

是的,請重新安裝DMX。第1#是通道(1-512),第2個PWM(0-255)。 我想了解什麼是從SD卡拉的變量。我以前的代碼有一個serial.println,儘管文本文件有4位數字節,結果爲'1'。 如果變量一次只有1個字節,那麼我可能是一個PWM值。如果變量「results」包含多個字節,那麼我是否需要一個循環來讀取第一個字節,將它寫入ch1 DMX,跳轉到第二個字節,寫入ch2 DMX等? leds [0]被定義爲CRGB,它在庫中意味着它擁有3個PWM值。 – joshjingles