流光溢彩代码验证不通过,求大神讲解-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 607|回复: 2

[已解决] 流光溢彩代码验证不通过,求大神讲解

[复制链接]
发表于 2022-3-23 23:46 | 显示全部楼层 |阅读模式
这是源代码
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
/*
* Arduino interface for the use of WS2812 strip LEDs
* Uses Adalight protocol and is compatible with Boblight, Prismatik etc...
* "Magic Word" for synchronisation is 'Ada' followed by LED High, Low and Checksum
* @author: Wifsimster <wifsimster@gmail.com>
* @library: FastLED v3.001
* @date: 11/22/2015
*/
#include "FastLED.h"
#define NUM_LEDS 167// 灯数量
#define DATA_PIN 4  //

// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
#define serialRate 115200

// Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;

// Initialise LED-array
CRGB leds[NUM_LEDS];

void setup() {              在这验证不通过
  // Use NEOPIXEL to keep true colors
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  // Initial RGB flash
  LEDS.showColor(CRGB(255, 0, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 255, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 255));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 0));

  Serial.begin(serialRate);
  // Send "Magic Word" string to host
  Serial.print("Ada\n");
}

void loop() {
  // Wait for first byte of Magic Word
  for(i = 0; i < sizeof prefix; ++i) {
    waitLoop: while (!Serial.available()) ;;
    // Check next byte in Magic Word
    if(prefix == Serial.read()) continue;
    // otherwise, start over
    i = 0;
    goto waitLoop;
  }

  // Hi, Lo, Checksum  
  while (!Serial.available()) ;;
  hi=Serial.read();
  while (!Serial.available()) ;;
  lo=Serial.read();
  while (!Serial.available()) ;;
  chk=Serial.read();

  // If checksum does not match go back to wait
  if (chk != (hi ^ lo ^ 0x55)) {
    i=0;
    goto waitLoop;
  }

  memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  // Read the transmission data and set LED values
  for (uint8_t i = 0; i < NUM_LEDS; i++) {
    byte r, g, b;   
    while(!Serial.available());
    r = Serial.read();
    while(!Serial.available());
    g = Serial.read();
    while(!Serial.available());
    b = Serial.read();
    leds.r = r;
    leds.g = g;
    leds.b = b;
  }

  // Shows new values
  FastLED.show();
}

微信截图_20220323234534.png
发表于 2022-3-24 09:02 | 显示全部楼层
程序中有多个setup
 楼主| 发表于 2022-3-25 14:43 | 显示全部楼层
奈何col 发表于 2022-3-24 09:02
程序中有多个setup

多谢!已解决
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:46 , Processed in 0.073771 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表