Hallo ich bin ganz neu hier und versuche mich an einem Arduino Projekt. Ich habe einen UNO und möchte mit der Adafruit NeoPixel Bibliothek eine Art Nanoleaf basteln.
Leider habe ich bei meinem Test ein Problem und zwar läuft die loop nur einmal am anfang durch und wiederholt sich dann nicht. Sehe ich irgendwo etwas nicht oder benutze ich evtl. was, was ich in dieser loop nicht verwenden sollte? Der Erste Durchgang funktioniert optisch wie gewollt nur leider wird dieser dann nicht fortgesetzt.
Hier mein Code:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define LED_PIN 6
#define LED_COUNT 36
int HEXA_NUM = 12; //Anzahl Hexagone oder Nanoleafs
int HEXA_LED = 3; //Anzahl LED pro Hexagon
int HEXA_DELAY = 1; //Wert zwischen Farbwechsel in Sekunden
int REIHENFOLGE[] = {7, 6, 4, 1, 0, 10, 3, 5, 2, 8, 11, 9};
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
// setup() function -- runs once at startup --------------------------------
//Farben
int az = 6; //Anzahl der Farben
int farbe[][3] = {
{250, 0, 0}, //rot
{0, 250, 0}, // grün
{160, 31, 240}, //Lila
{255, 165, 0}, //Orange
{0, 255, 255}, //Türkis
{0, 0, 250}}; //blau
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
int start = 1;
int newcolor = 0;
while(start <= HEXA_NUM){
if(newcolor == az){newcolor = 0;}
int endR = farbe[newcolor][0]; //Random RED value
int endG = farbe[newcolor][1]; //Random GREEN value
int endB = farbe[newcolor][2]; //Random BLUE value
int FIRST_LED = start * HEXA_LED - HEXA_LED;
int a = 0;
int i = FIRST_LED;
//int i = 5;
while(a < HEXA_LED){
strip.setPixelColor(i, endR, endG, endB);
a++;
i++;
}
strip.show();
start ++;
newcolor ++;
}
}
int hexa = 1;
int newcolor = 2;
int r;
int g;
int b;
int newR, newG, newB, HEXA_AKT, FIRST_LED, endR, endG, endB;
int finish;
void loop(){
finish = 0;
if(newcolor == az){newcolor = 0;}
//if(hexa == (HEXA_NUM + 1)){hexa = 1;}
HEXA_AKT = hexa;
FIRST_LED = HEXA_AKT * HEXA_LED - HEXA_LED;
long lngRGB = strip.getPixelColor(FIRST_LED);
uint8_t startR = (uint8_t)((lngRGB >> 16) & 0xff),
startG = (uint8_t)((lngRGB >> 8) & 0xff),
startB = (uint8_t)(lngRGB & 0xff);
//Test für Startfarbe
//int startR = 250;
//int startG = 0;
//int startB = 0;
endR = farbe[newcolor][0]; //Random RED value
endG = farbe[newcolor][1]; //Random GREEN value
endB = farbe[newcolor][2]; //Random BLUE value
while(finish < 1){
if(startR > endR){
startR = startR - 1;
}else if(startR < endR){
startR = startR + 1;
}else{
newR = startR;
r = 1;
}
if(startG > endG){
startG = startG - 1;
}else if(startG < endG){
startG = startG + 1;
}else{
newG = startG;
g = 1;
}
if(startB > endB){
startB = startB - 1;
}else if(startB < endB){
startB = startB + 1;
}else{
newB = startB;
b = 1;
}
if(r == 1 && g == 1 && b ==1){finish = 1;}
if(startR > 255){startR = 255;}
if(startG > 255){startG = 255;}
if(startB > 255){startB = 255;}
newR = startR;
newG = startG;
newB = startB;
int a = 0;
int i = FIRST_LED;
//int i = 5;
while(a < HEXA_LED){
strip.setPixelColor(i, newR, newG, newB);
a++;
i++;
}
strip.show();
delay(10);
}
hexa ++;
newcolor ++;
delay(HEXA_DELAY * 1000);
}
Vielleicht sieht ja einer was ich dort falsch mache. Vielen Dank schonmal!