Serialization 我将在循环部分使用 int缓冲垃圾[1]//这是让整个事情顺利进行的关键。我们需要 //越过从VIXEN发送到ARDUINO MEGA的第一个神秘字节 //灯光软件。所以我们创建了一个变量,我们将在代码的循环部分使用它。 无效设置(){ 延迟(1000);

Serialization 我将在循环部分使用 int缓冲垃圾[1]//这是让整个事情顺利进行的关键。我们需要 //越过从VIXEN发送到ARDUINO MEGA的第一个神秘字节 //灯光软件。所以我们创建了一个变量,我们将在代码的循环部分使用它。 无效设置(){ 延迟(1000);,serialization,arduino,pixels,led,Serialization,Arduino,Pixels,Led,我将在循环部分使用 int缓冲垃圾[1]//这是让整个事情顺利进行的关键。我们需要 //越过从VIXEN发送到ARDUINO MEGA的第一个神秘字节 //灯光软件。所以我们创建了一个变量,我们将在代码的循环部分使用它。 无效设置(){ 延迟(1000); 串行开始(波特率); 引脚模式(LED_引脚1,输出);//将引脚设置为输出。引脚1是Arduino板上的引脚6。 引脚模式(LED_引脚2,输出);//将引脚设置为输出。引脚2是Arduino板上的引脚7。 //该行设置第一个使用FastL

我将在循环部分使用 int缓冲垃圾[1]//这是让整个事情顺利进行的关键。我们需要 //越过从VIXEN发送到ARDUINO MEGA的第一个神秘字节 //灯光软件。所以我们创建了一个变量,我们将在代码的循环部分使用它。 无效设置(){ 延迟(1000); 串行开始(波特率); 引脚模式(LED_引脚1,输出);//将引脚设置为输出。引脚1是Arduino板上的引脚6。 引脚模式(LED_引脚2,输出);//将引脚设置为输出。引脚2是Arduino板上的引脚7。 //该行设置第一个使用FastLED运行的像素条 快速发光二极管(发光二极管1,发光二极管数)。设置校正(典型称为触发); //这一行设置第二个像素条,使用FastLED运行 快速发光二极管(发光二极管2,发光二极管数)。设置校正(典型称为触发); } void循环(){ 如果(Serial.available()>=0){//如果串行流中有数据 //bufferGarbage是捕获遇到的垃圾的第一个字节。 //如果没有此功能,LED将不同步。 //在我的例子中,如果我没有捕获这个字节,我的 //第二个LED条将与最后一个LED条上的颜色代码相匹配 //第一条带的像素。我们不使用这个字节。 //但是我们需要从串行流中读取它,这样我们就可以转到 //流中的下一个字节。 bufferGarbage[0]=Serial.read(); //然后我们需要填充leds1阵列,以便FastLED可以告诉像素该做什么。 //我们在条带中有50个像素,每个像素都有一个使用 //红色、绿色和蓝色属性。因此,对于每个LED,我们需要捕获3个 //来自串行流的字节。50个LED*3个字节表示我们需要读取 //来自串行流的150字节数据。 对于(g=0;g不幸的是,这并没有完全起作用。这是我尝试的;if(Serial.available()>=0){Serial.readBytes((char*)led,NUM_led*3);byte relay=Serial.read();}FastLED.show()digitalWrite(PIN_NUMBER,relay);指示灯的输出错误。LED闪烁随机颜色,控制常规指示灯的引脚随LED闪烁,而不是应打开/关闭指示灯。尝试在
Serial.readBytes((char*)LED,NUM_LED*3)之后添加延迟;
类似
延迟(10)的内容;
确保在调用
字节继电器=Serial.read()之前字节到达
谢谢你的建议,但即使有延迟,我也得到了相同的结果。我也尝试了不同的延迟长度,1、10、25、50和100。LED的随机颜色闪烁,常规灯的继电器随着LED闪烁,并且当常规灯应该亮起时,单个LED也会亮起。这就像我的字节混乱了,或者有tra字节正在偏离模式。您是在一个流og中发送151字节吗?您是先发送150字节,然后再发送最后一个字节吗?我不确定是否能够回答这个问题。但是,我可以告诉您,我在Vixen中使用的一个控制器有151个输出(150个LED,1个常规灯)。这意味着我有两个“通道”还是两个数据流?
          Serial.readBytes((char*)leds, NUM_LEDS * 3);//buffer to store things in, length (number of bytes to read)
          FastLED.show();//refresh the pixel LED's
#define CHANNEL_01 7 //Pin #7 on the Arduino Mega board

   void setup()
    {
      // Begin serial communication
      Serial.begin(BAUD_RATE);
      #define CHANNEL_COUNT 1 

    int channels[] = {CHANNEL_01}
    int incomingByte[16];
    // Define baud rate. This figure must match that of your profile configuration in Vixen!
    #define BAUD_RATE 9600 


      // Set up each channel as an output
      for(int i = 0; i < CHANNEL_COUNT; i++)
      {
        pinMode(channels[i], OUTPUT);
      }
    }

void loop()
{
  if (Serial.available() >= CHANNEL_COUNT)
  {
    // Read data from Vixen, store in array
    for (int i = 0; i < CHANNEL_COUNT; i++)
    {
      incomingByte[i] = Serial.read();
    }
    // Write data from array to a pin on Arduino
    for (int i = 0; i < CHANNEL_COUNT; i++)
    {
      digitalWrite(channels[i], incomingByte[i]);
    }
  }
}
bool relayState[8];

Serial.readBytes((char*)leds, NUM_LEDS * 3);

byte relays = Serial.read();

for(byte i=0;i<8;i++){
  relayState[i] = bitRead(relays, i);
}

for(byte i=0;i<8;i++) {
  digitalWrite(relay[i], relayState[i]);
}
#define PIN1 7 //Pin number seven
#define PIN2 6 //Pin number six
#define PIN3 5 //Pin number five
#define PIN4 4 //Pin number four

#define BAUD_RATE 9600 //just running 4 relay switches so we don't need much speed
#define CHANNEL_COUNT 4 //there are 4 channels coming from the Vixen controller

int bt[4]; //a variable we will use in the loop section of code
int x; //another variable we will use in the loop section of code

void setup() {
    delay(1000); //a little delay to give Uno some time on startup
    Serial.begin(BAUD_RATE); //set the baud rate of the serial stream
    pinMode(PIN1, OUTPUT); //set the four pins on the Arduino Uno to output
    pinMode(PIN2, OUTPUT);
    pinMode(PIN3, OUTPUT);
    pinMode(PIN4, OUTPUT);

}

void loop() {
    if (Serial.available() >= CHANNEL_COUNT) { 
        for (X = 0; x < CHANNEL_COUNT; x++) { //for every channel...
            bt[x] = Serial.read(); //we read a byte from the serial stream buffer and store it in an array for later use
        }

        digitalWrite(PIN1, bt[0]);  //we tell the pins on the arduino what to do... 
        digitalWrite(PIN2, bt[1]);  //using the array of integers that holds the byte values from the serial stream...
        digitalWrite(PIN3, bt[2]); 
        digitalWrite(PIN4, bt[3]);

    }   

}
#include <FastLED.h> //include the FastLED library in the Arduino project
#define LED_PIN1 7 //I am going to run one strip of 50 LEDs off of pin 7 on the MEGA
#define LED_PIN2 6 //I am going to run a second strip of 50 LEDs off of pin 6 on the MEGA
#define BAUD_RATE 115200 
#define NUM_LEDS 50

//It took me some time to figure out that my two pixel strips are set 
//to different color codes. Why? I don't know, but they are.  
#define RGB_ORDER RGB //one of my pixel strips is set to use RGB color codes
#define BRG_ORDER BRG //the second strip came from the factory with BRG color codes

#define LED_TYPE WS2811 //what type of LEDs are they? Mine are WS2811, yours may be different.

//create an array to hold the FastLED CRBG code for each of the 50 pixels in the 
//first strip.
CRGB leds1[NUM_LEDS]; 

//create another array to hold the FastLED CRBG codes for each of the 50 pixels in 
//the second strip.
CRGB leds2[NUM_LEDS]; 

int g; //a variable we will use in the loop section

int bufferGarbage[1]; //THIS IS THE KEY TO MAKING THIS WHOLE THING WORK. WE NEED TO 
 //GET PAST THE FIRST MYSTERY BYTE THAT IS SENT TO THE ARDUINO MEGA FROM THE VIXEN 
 //LIGHTS SOFTWARE. So we create a variable we will use in the loop section of code. 

void setup() {
    delay(1000);
    Serial.begin(BAUD_RATE);
    pinMode(LED_PIN1, OUTPUT); //set our pins to output. PIN1 is pin 6 on the Arduino board.
    pinMode(LED_PIN2, OUTPUT); //set our pins to output. PIN2 is pin 7 on the Arduino board.

     //This line sets up the first pixel strip to run using FastLED
    FastLED<LED_TYPE, LED_PIN1, RGB_ORDER>(leds1, NUM_LEDS).setCorrection(TypicalLEDStrip); 

    //This line sets up the second pixel strip to run using FastLED
    FastLED<LED_TYPE, LED_PIN2, BRG_ORDER>(leds2, NUM_LEDS).setCorrection(TypicalLEDStrip); 
}

void loop() {
    if (Serial.available() >= 0) { //if there is data in the serial stream
           //bufferGarbage is to capture the first byte of garbage that comes across.
           //Without this the LED's are out of sync. 
           //In my case if I didn't capture this byte the first pixel on my 
           //second LED strip would match the color code that should be on the last 
           //pixel of the first strip. We don't do anything with this byte.
           //but we need to read it from the serial stream so we can move to the 
           //next byte in the stream.
           bufferGarbage[0] = Serial.read();  

        //then we need to populate the leds1 array so FastLED can tell the pixels what to do.
        //We have 50 pixels in the strip and each pixel has a CRGB property that uses 
        //a red, green, and blue attribute. So for each LED we need to capture 3
        //bytes from the serial stream. 50 LEDs * 3 bytes each means we need to read
        //150 bytes of data from the serial stream.
        for (g = 0; g < NUM_LEDS; g++) {
            Serial.readBytes( ( char*)(&leds1[g], 3);
        }
        for (g = 0; g < NUM_LEDS; g++) {//then we read the next 150 bytes for the second strip of LEDs
            Serial.readBytes( ( char*)(&leds2[g], 3);
        }

        FastLED.show(); //then we tell FastLED to show the pixels!

    }
}