1

任何人都知道我从文本文件 (SD) 中提取数据并沿 DMX 发送时出错的地方?该代码适用于 P9813 部分,DMX 一般适用,但不适用于 SD 数据。

粘贴代码在这里

我相信我的问题在第 68 行。我认为这是读取太多值。IE currentColor 存储 5 个值(5 个灯)与 1 个十六进制或 3xR/G/B。

SD 中供考虑的值是...“727a 6276 3030 ...”。我相信这些字节应该是每个 DMX 通道的 PWM 值,不是吗?

谢谢</p>

4

2 回答 2

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();
}
于 2016-04-27T18:15:50.643 回答
0

感谢您的帮助,现在一切正常。

结果如下:http: //pastebin.com/wHAT6dZB

于 2016-05-01T03:23:11.457 回答