I want to create a LED animation using Adafruit_NeoPixel library.
Unfortunately I'm struggling with a probably dump thing. For some reason the strip does not anymore work when using a certain array access if (led_states[pixel] > 0) {
. Meaning even strip.clean()
+ strip.show()
in setup doesn't work anymore. May you can tell me what I did wrong because I really don't get it. PS: I'm using ATTiny85 with arduino framework if that helps.
#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();
}
}
if (led_states[pixel] > 0) { // <---- strip works when commenting this block SWSERIAL.printf("V: %i\n", led_values[pixel]); }
..to just...SWSERIAL.printf("V: %i\n", led_values[pixel]);
...and see if that works. (My guess is that it will not) – bigjosh Dec 07 '21 at 04:49