我想使用 Adafruit_NeoPixel 库创建一个 LED 动画。不幸的是,我正在为一个可能倾倒的事情而苦苦挣扎。由于某种原因,当使用某个数组访问时,条带不再起作用if (led_states[pixel] > 0) {
。这意味着即使strip.clean()
+strip.show()
在 setup 中也不再起作用。愿你能告诉我我做错了什么,因为我真的不明白。PS:如果有帮助,我正在使用带有 arduino 框架的 ATtiny85。
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#define LED_AMOUNT 30
#define LED_DATA_PIN PB1
SoftwareSerial SWSERIAL(0, PB3); // RX, TX
Adafruit_NeoPixel strip(LED_AMOUNT, LED_DATA_PIN, NEO_GRB + NEO_KHZ800);
int step = 2;
int max = 255 - step;
int led_states[LED_AMOUNT] = { 0 };
int led_values[LED_AMOUNT] = { 0 };
unsigned long last_frame = 0;
unsigned long last_change = 0;
void led_test_setup() {
delay(5000);
SWSERIAL.begin(9600);
SWSERIAL.println("Setup");
randomSeed(analogRead(0));
strip.begin();
strip.clear();
strip.show();
}
void led_test_loop() {
unsigned long now = millis();
if (last_change + 200 < now) {
int pixel = random(0, LED_AMOUNT);
led_states[pixel] = 1;
led_values[pixel] = 0;
last_change = now;
}
if (last_frame + 10 < now) {
for (int pixel = 0; pixel < LED_AMOUNT; pixel++) {
if (led_states[pixel] > 0) { // <---- strip works when commenting this block
SWSERIAL.printf("V: %i\n", led_values[pixel]);
}
strip.setPixelColor(pixel, led_values[pixel], led_values[pixel], led_values[pixel]);
}
last_frame = now;
strip.show();
}
}