Hallo Leute!
Im Prinzip sollte das ja nicht unter Cross-posting fallen, aber ich verweise auch gern nochmal an meinen Beitrag im Programming-Questions Bereich NeoPixel Multi LED Controller
Ursprünglich ging es um das simultane Ansteuern von 2 NeoPixel Strips mit unabhängigen Tastern für jeweils Bewegungsmuster und Farbe.
Da ich dort aber überhaupt nicht weiter komme versuche ich nun erstmal einen Strip mit den gewünschten Funktionen anzusteuern.
Vermutlich sind meine Englischkenntnisse einfach zu schlecht um mein Vorhaben richtig erklären zu können.
Unabhängig davon ist das Problem auf das ich jetzt gestoßen bin:
der erste "Color-Fade Modus" den ich implementieren möchte:
Der ganze Strip (alle LEDs gleich) soll von Rot über Grün zu Blau wieder zu Rot durch alle Farben faden.
Bei mir fadet er nur von Rot nach Grün und fängt dann wieder bei Rot an.
Ich vermute, dass ich die Funktion Wheel() nicht entgültig verstanden habe.
Ich habe mal einen festen wert (170) an Wheel() übergeben.
Eigentlich sollte der 32bit Wert (130560) der von Wheel() zurückgegeben wird Blau sein.
Der Strip zeigt aber Grün an...
Ich habe den Code mal angehängt.
Wäre schön, wenn mir dazu jemand etwas sagen könnte ![]()
#include <Adafruit_NeoPixel.h>
// Digital IO pin connected to the buttons.
#define BTN01_PIN 2 // This will be
#define BTN02_PIN 5 // driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
// Digital IO pin connected to the NeoPixels.
#define PIXEL_PIN 6 // BOTTOM STRIP
// LED Anzahl
#define PIXEL_COUNT 8
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
int modeType = 0;
int colrType = 0;
int pixelPos = 0;
int ledClock = 0;
bool oldState01 = HIGH;
bool oldState02 = HIGH;
uint32_t pixelColor = strip.Color(0, 0, 0);
byte color = 0;
void colorWipe(int strip, int color[]);
int pickcolor(int c);
uint32_t Wheel(byte WheelPos);
void setup() {
pinMode(BTN01_PIN, INPUT_PULLUP);
pinMode(BTN02_PIN, INPUT_PULLUP);
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
ledClock ++; //Clock to sync different speed rates of the modes
if (ledClock > 1000) //Clock Loop
ledClock = 1;
Serial.print("MODE: ");
Serial.print(modeType);
Serial.print(" | COLR: ");
Serial.print(colrType);
Serial.print(" | COLOR: ");
Serial.print(color);
Serial.print(" | PIXEL: ");
Serial.print(pixelPos);
Serial.print(" | pixel.Color: ");
Serial.println(pixelColor);
if(pixelPos == PIXEL_COUNT)
pixelPos = 0;
bool newState01 = digitalRead(BTN01_PIN);
bool newState02 = digitalRead(BTN02_PIN);
// Check if state changed from high to low (button press).
if (newState01 == LOW && oldState01 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState01 = digitalRead(BTN01_PIN);
if (newState01 == LOW) {
colrType++;
pixelPos = 0;
if (colrType > 6)
colrType=0;
}
}
// Set the last button state to the old state.
oldState01 = newState01;
// Check if state changed from high to low (button press).
if (newState02 == LOW && oldState02 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState02 = digitalRead(BTN02_PIN);
if (newState02 == LOW) {
modeType++;
pixelPos = 0;
if (modeType > 1)
modeType=0;
}
}
// Set the last button state to the old state.
oldState02 = newState02;
pickColor(colrType); //Get Color for strip
startShow(modeType); //Start strip with selected Mode
}
void pickColor(int c) {
switch(c){
case 0: {
pixelColor = strip.Color(255, 0, 0); // RED
}
break;
case 1: {
pixelColor = strip.Color(0, 255, 0); // GREEN
}
break;
case 2: {
pixelColor = strip.Color(0, 0, 255); // BLUE
}
break;
case 3: {
pixelColor = strip.Color(255, 255, 255); // WHITE
}
break;
case 4: {
pixelColor = strip.Color(15, 04, 87); // rainbow -> LATER
}
break;
case 5: {
Wheel(color) ;
//Wheel(color & 255) ; // color fade
color++;
}
break;
case 6: {
pixelColor = strip.Color(0, 0, 0); // Black/off
}
break;
}
}
void startShow(int mode) {
switch(mode){
case 0: {
colorWipe();
}
break;
case 1: {
colorWipe();
}
break;
case 2: {
colorWipe();
}
break;
case 3: {
colorWipe();
}
break;
}
}
// MODE 01 COLOR WIPE - FILL LEDS ONE AFTER THE OTHER-----------------------------------------------------------------------------------------------------------------
void colorWipe() {
uint16_t i;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, pixelColor);
}
strip.show();
}
//RAINBOW COLOR
/*void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
/*
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
//Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
*/
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte wheelPos) {
wheelPos = 255 - wheelPos;
if(wheelPos <= 85) {
Serial.println("TEST bis 85!!!");
pixelColor = strip.Color(255 - wheelPos * 3, 0, wheelPos * 3);
}
if(wheelPos > 85 && wheelPos <= 170) {
Serial.println("TEST 86 - 170!!!");
wheelPos -= 85;
pixelColor = strip.Color(0, wheelPos * 3, 255 - wheelPos * 3);
}
wheelPos -= 170;
pixelColor = strip.Color(wheelPos * 3, 255 - wheelPos * 3, 0);
}