【发布时间】:2015-11-12 01:12:19
【问题描述】:
我正在尝试为DMX 软件Freestyler 创建一个 Arduino 接口,但由于知道接收到的数据的编码,因此难以解析接收到的数据。
下图是我连接到Freestyler 的串行监视器,用于查看传入的数据,格式非常简单,每个通道 3 个字节。第一个字节是startOfMessage,第二个字节是通道号,第三个字节是通道值。
串行监视器显示为十六进制和十进制。
为了测试,我试图在 startOfmessage(它是一个常量)被正确解析时打开一个 LED。
byte myByte;
void setup(void){
Serial.begin(9600); // begin serial communication
pinMode(13,OUTPUT);
}
void loop(void) {
if (Serial.available()>0) { // there are bytes in the serial buffer to read
while(Serial.available()>0) { // every time a byte is read it is expunged
// from the serial buffer so keep reading the buffer until all the bytes
// have been read.
myByte = Serial.read(); // read in the next byte
}
if(myByte == 72){
digitalWrite(13,HIGH);
}
if(myByte == 48){
digitalWrite(13,HIGH);
}
delay(100); // a short delay
}
}
谁能给我指明正确的方向?
【问题讨论】:
标签: parsing arduino serial-port dmx512