Good evening, I have a problem with some ws2812 LEDs, I'm trying to make a 7-segment number, but when I go to farm the numbers the first 3 LEDs always stay on even when they shouldn't, I tried to test only the first three LEDs even individually and they respond to commands, but when I send this sketch, any number I ask them to make the first three always on, could you help me understand what the problem could be? thank you very much below is the sketch I'm using, thanks again.`
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define NUM_LEDS 21 // 7 segmenti * 3 LED per segmento
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
// Mappatura dei segmenti per i numeri 0-9
const int segment[10][7] = {
{0, 1, 2, 3, 4, 5}, // 0
{1, 2 }, // 1
{0, 1, 3, 4, 6}, // 2
{0, 1, 2, 3, 6}, // 3
{1, 2, 5, 6}, // 4
{0, 2, 3, 5, 6}, // 5
{0, 2, 3, 4, 5, 6}, // 6
{0, 1, 2}, // 7
{0, 1, 2, 3, 4, 5, 6}, // 8
{0, 1, 2, 3, 5, 6} // 9
};
// Imposta qui il numero iniziale
int currentNumber = 2; // Cambia questo valore per impostare il numero iniziale
void setup() {
strip.begin();
strip.show(); // Spegni tutti i LED
}
void loop() {
updateDisplay(currentNumber);
delay(1000); // Aspetta un secondo
}
void updateDisplay(int number) {
// Spegni tutti i LED
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0)); // Spegni il LED
}
// Accendi i segmenti per il numero corrente
for (int i = 0; i < 7; i++) {
int segmentIndex = segment[number][i];
for (int j = 0; j < 3; j++) {
int ledIndex = segmentIndex * 3 + j; // Ogni segmento ha 3 LED
if (ledIndex < NUM_LEDS) {
strip.setPixelColor(ledIndex, strip.Color(255, 0, 0)); // Rosso
}
}
}
strip.show();
}