Arduino 控制 ledstrip 与新像素卡住

Arduino controlling ledstrip with neopixel stuck

本文关键字:像素 控制 ledstrip 新像素 Arduino      更新时间:2023-10-16

我尝试用我的 pi 2812b LED 灯条控制 rgb ws3b LED 灯条。这工作正常。现在我想用我的Arduino Nano来做这件事。控件本身有效。如果我将一些代码放入循环函数中,一切正常。但是如果我想通过函数调用代码,比如void colorWipe(({ change color },我在循环中调用colorWipe((,它不再改变颜色。为什么???

这是代码:

#include <Adafruit_NeoPixel.h>
#define shortStrip 2
#define longStrip 3
#define led_count_short 23
#define led_count_long 277
Adafruit_NeoPixel strip_short = Adafruit_NeoPixel(led_count_short, shortStrip, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_long = Adafruit_NeoPixel(led_count_long, longStrip, NEO_GRB + NEO_KHZ800);
void setup(){
  Serial.begin(9600);
  strip_short.begin();
  strip_short.setBrightness(50);
  strip_short.show();
  Serial.println("Short strip is running!");
  delay(50);
  strip_long.begin();
  strip_long.setBrightness(50);
  strip_long.show();
  Serial.println("Long strip is running!");
  delay(50);
}
void loop(){
  colorWipe(10, strip_long, led_count_long, 255, 255, 255);
  Serial.println("Finished Long");
  delay(1000);
  colorWipe(10, strip_long, led_count_long, 255, 0, 0);
  Serial.println("This too Long");
  delay(1000);
}
void colorWipe(uint8_t wait, Adafruit_NeoPixel strip, int led_count, int r, int g, int b){
 Serial.print("1");
 for(int i = 0; i < led_count; i++){
  strip.setPixelColor(i, strip.Color(r,g,b));
  strip.show();
  delay(wait);
 } 
 Serial.print("2");
 return;
}

是的,我确实有 2 个 LED 灯条,但循环中只调用了 1 个。我的串行显示器打印一切正常,但颜色不会改变。我尝试了多种颜色。第一个 colorWipe(( 有效,之后的所有颜色擦除都不起作用。

请帮助

谢谢

你试过使用引用吗?将colorWipe更改为

void colorWipe(uint8_t wait, Adafruit_NeoPixel & strip, int led_count, int r, int g, int b)

我的猜测是,当您复制strip对象时,不再可能访问setPixelColorshow。应使用在代码开头声明的对象,这可以使用引用来完成。