2016-04-27 74 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