Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



LED-matrix with WS2...
 
Share:
Notifications
Clear all

[Solved] LED-matrix with WS2812b LED-stripes project

8 Posts
2 Users
0 Likes
4,469 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2679
Topic starter  

The sources of Trollo_meo's LED matrix project and some context;

I’m having a problem with my project I’ve made with your projects…

I would like to do an LED-matrix with WS2812b LED-stripes.

So I picked 6 different project’s from this website and I put them into my sketch.

Now I’m having a problem…

I wanted to work with an HIGH respective LOW pegel.

Everything is good and at the right pin I’m having HIGH if I close the switch.

But the program doesn’t start my function where the LED’s will start to work…

I’m sorry for my bad english I’m native german speaker…

It’s a pretty big project sorry.

//LED-Matrix
//6 different modes can be switched with 6 switches
//Uster
//11.11.2019
//Hier könnte Ihre Werbung stehen
#include "FastLED.h" //the FastLED-h Library getts included
#include <Adafruit_NeoPixel.h> //the Adafruit_NeoPixel.h Library getts included
#define NUM_LEDS 30 //the Variable NUM_LEDS is defined with 30
#define NUMPIXELS 30 //the amount of LED's is defined with 30
#define PIN 6
int aufblinkeninput = 12; //declaration of the pin 12 as aufblinkeninput
int fadeinput = 11; //declaration of the pin 11 as fadeinput
int fadeindermittetreffeninput = 10; //declaration of the pin 10 as fadeindermittetreffeninput
int funmodeinput = 9; //declaration of the pin 9 as funmodeinput
int geilerfadeinput = 8; //declaration of the pin 8 as geilerfadeinput
int rainbowfadeinput = 7; //declaration of the pin 7 as rainbowfadeinput
void TwinkleRandom(); //declaration of the function TwinkleRandom
void addtoloop2(); //declaration of the function addtoloop2
void fade(); //declaration of the function fade
void addtoloop3(); //declaration of the function addtoloop3
void fader(); //declaration of the function fader
void rainbowCycle(uint8_t); //declaration of the function rainbowCycle
void setAll(int, int, int); //declaration of the function setAll
void fadeall(int); //declaration of the function fadeall
void showStrip(); //declaration of the function showStrip
void brighten(); //declaration of the function brighten
void darken(); //declaration of the function darken


int i = 0;

//CRGB leds[NUM_LEDS];
CRGBArray<30> leds;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800); //the amount of LED's is 30
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //allows communication with a display -> here with a LED strip
  LEDS.addLeds<NEOPIXEL,PIN>(leds, NUM_LEDS);                               
  LEDS.addLeds<WS2811, PIN,BRG>(leds,NUM_LEDS); //out of the FastLED-library, does pinsettings
  strip.begin(); //declaration of the function strip.begin, starts the strip
  strip.show(); //strip.show light the LED's
  FastLED.addLeds<NEOPIXEL,6>(leds,NUM_LEDS);
  LEDS.setBrightness(255); //the brightness is setted to 255 (maximum)
  pinMode(aufblinkeninput, INPUT); //declaration of the pin aufblinkeninput as input
  pinMode(fadeinput, INPUT); //declaration of the pin fadeinput as input
  pinMode(fadeindermittetreffeninput, INPUT); //declaration of the pin fadeindermittetreffen as input
  pinMode(funmodeinput, INPUT); //declaration of the pin funmode as input
  pinMode(geilerfadeinput, INPUT); //declaration of the pin geilerfadeinput as input
  pinMode(rainbowfadeinput, INPUT); //declaration of the pin rainbowfadeinput as input
}
void loop() {
  //1. aufblinken 
if( aufblinkeninput == HIGH) {                                                           
TwinkleRandom(); //if the pin aufblinkeninput is HIGH the function TwinkleRandom starts
}
//2. fade
if(fadeinput == HIGH){                                                                   
  brighten(); //if the pin fadeinput is HIGH first the function brighten
  darken(); //second the function darken starts                                                                          
}
//3. fadeindermittetreffen
if(fadeindermittetreffeninput == HIGH){
  addtoloop2(); //if the pin fadeindermittetreffeninput is HIGH the function addtoloop2 starts
}
//4. funmode
if(funmodeinput == HIGH) {
  addtoloop3(); //if the pin funmodeinput is HIGH the function addtoloop3 starts
}
//5. geilerfade
if(geilerfadeinput == HIGH) {
  fader(); //if the pin geilerfadeinput is HIGH the function fader starts
}
//6. rainbowfade
if(rainbowfadeinput == HIGH) {
  rainbowCycle(75); //if the pin rainbowfadeinput is HIGH the function rainbowCycle starts
}
}

//definitionen
//ALLES DAS NICHT IM LOOP IST!!!!
//1. aufblinken
void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) { //definition of the function TwinkleRandom
  setAll(0,0,0);
  for (int i=0; i<Count; i++) {
    fadeall(fadespeed);
    setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) { 
      setAll(0,0,0); 
    }
  }
// delay(SpeedDelay);  
}
void setPixel(int Pixel, byte red, byte green, byte blue) { //definition of the function setPixel from the function TwinkleRandom
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) { //definition of the function setAll from the function TwinkleRandom
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}
void showStrip() { //definition of the function showStrip from the function TwinkleRandom
  FastLED.show();
}
void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds.nscale8(scale); } } //definition of the function fadeall from the function TwinkleRandom
  
//2. fade
void brighten() {
  uint16_t i, j;
  for (j = 0; j < 255; j++) { //j (brightness of the LED) getts brightened up to 255
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j); //definition of the color white, all of RGB-LED's have the same numeric
    }
    strip.show();
    delay(10); //10er delay, break of 10 miliseconds
    
  }
  //delay(1500);
}
// 255 to 0
void darken() {
  Serial.begin(9600);
  uint16_t i, j;
  for (j = 255; j > 0; j--) { //same function like brighten but the brightness getts increased
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j);
    }
    strip.show();
    delay(10);
    Serial.println(j);
  }
  delay(1500); //1500 milisecond delay (1.5 seconds)
}
//3.fadeindermittetreffen
void addtoloop2() {
  static uint8_t hue;
  EVERY_N_MILLISECONDS(100){ //repeat the function every 100 miliseconds
    leds.fadeToBlackBy(180);
    if (i<NUM_LEDS/2){
      leds = CHSV(hue++,255,255);
      i++;
    }else{
      i=0;
    }
    leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0); //the amount of LED's getts bisect that the LED's meet in the middle
    FastLED.show();
  }
}
//4. funmode
void addtoloop3(){
                                                                                           // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); //Red
  colorWipe(strip.Color(0, 255, 0), 50); //Green                                         
  colorWipe(strip.Color(0, 0, 255), 50); //Blue
                                                                                           // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); //White
  theaterChase(strip.Color(127, 0, 0), 50); //Red
  theaterChase(strip.Color( 0, 0, 127), 50); //Blue
  
  rainbow(20);
  rainbowCycle(20);                                                                       
  theaterChaseRainbow(50);
}
                                                                                           // Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) { //the LED's brighten after each other in a definited color                               
  for(uint16_t i=0; i<strip.numPixels(); i++) { //i is the variable for the LED's
      strip.setPixelColor(i, c);
      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.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) { //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c); //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
      }
    }
  }
}
                                                                                        //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) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); //the colors pulsate
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

//5.geilerfade
void fader(){
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the brightness is setted to 255
    int r = 255; //the red LED is at maximum brightness -> the led is red
    int g = 0; //the green LED is dark
    int b = colorStep; //the blue LED brighten up until the red LED is covered
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) { //the brightness lowers 255 to 0
    int r = colorStep; //red getts increased with the variable colorstep and getts covered with the blue
    int g = 0; //the green LED is dark
    int b = 255; //red LED fades to blue
    for(int x = 0; x < NUM_LEDS; x++){                                            
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the LED getts brighter
    int r = 0; //the red LED is dark
    int g = colorStep; //the green LED brighten up until the blue LED is covered
    int b = 255; //the color fades from blue to green
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 0; //the red LED is dark
    int g = 255; //the blue LED is bright
    int b = colorStep; //the green LED darken
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {
    int r = colorStep; //the red LED brightens and covers the blue LED                                                
    int g = 255; //the blue LED is bright
    int b = 0; //the blue LED is dark  
    for(int x = 0; x < NUM_LEDS; x++){ //the amount of the brighten LED's counts up
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 255; //the red LED is bright
    int g = colorStep; //the green LED getts darker
    int b = 0; //the blue LED is dark                                                                  
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
  delay(10); 
  FastLED.show();
  }
}
//6. rainbowfade //definition not necessary it got defined before


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2679
Topic starter  

Even though this is an English forum; if you really get stuck with the English language, throwing in a few German expressions is OK.
I do speak German as well but would like to keep the forum posts as readable as possible for other users. 

I'm not 100% clear of the issue you're running into, but I did notice something in your loop() that will cause issues;

void loop() {
  //1. aufblinken 
  if (aufblinkeninput == HIGH) {
    TwinkleRandom(); //if the pin aufblinkeninput is HIGH the function TwinkleRandom starts
  } ...
}

I see you want to test if a button state is HIGH or not.
You properly define the button on that pin as such in setup().

However, ... you never read the actual button state. In your code you read the value of the variable (holding the pin number) instead.

So in setup() you set a particular Arduino pin to be an input for a button:

pinMode(aufblinkeninput, INPUT);

But in the loop you're testing this fixed number (aufblinkeninput) to be HIGH or not.
However, this would be the pin number for that button (int aufblinkeninput = 12; ), and not the actual value of what is going on on that pin.
The state of the button is not being read either. You'll need to use the "digitalRead()" function for that.

A short recap for that particular example (you'll need to apply this to the other variables as well)

This is what you had:

int aufblinkeninput = 12;
...
void setup() {
  ...
  
  pinMode(aufblinkeninput, INPUT);
  ...
}
void loop() {
  ...
  
 if( aufblinkeninput == HIGH) {                                                           
   TwinkleRandom();
 }
 
 ...
}

Now change that to this (eg. you will need to apply this to the other buttons as well;

#define aufblinkeninput 12  // define the pin for this button
...
void setup() {
  ...
  
  pinMode(aufblinkeninput, INPUT); 
  ...
}
void loop() {
  ...
  
  if (digitalRead (aufblinkeninput) == HIGH) {
    TwinkleRandom(); 
  }
  ...
}

(I made the changes bold)

Hope this helps you get further with your project 


   
ReplyQuote
(@trollo_meo)
New Member
Joined: 4 years ago
Posts: 4
 

So if u r having problems with my project I'll try to explain what I wanted to do...

So my idea is that I'm having a wooden board with an WS2812b LED-stripe mounted on it.

This stripe will show up in different modes.

(I've used Random color Twinkle ->aufblinken and Rainbow Cycle ->rainbowfade)

So now I'm having the programmed modes and I want to have 6 different switches where I can switch between those modes.

I've started with a switch case but it didn't work....

So I picked some if else.

Now I'm having the problem that if I have a logical 1 at the pin 12 for example (for aufblinken in this case) there's no output at my pin 6 wich is connected to the LED-stripe.

I'm sure that my mistake is in the programm cause everything works well in the montage to my arduino nano...

Myb that's the problem.

I havn't used other Arduinos except the Nano until yet.

Myb this helps u to understand what I'm struggeling with.

Now I've took the advices u gave me and switched everything in the programm...

But I'm having an error message:

Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P"

In file included from Z:\Projekte, Bestellungen & Messungen\Projekte\Hauptprojekte\Projekt #9 Arduino\Versuch einbindung alle Projekt\Projekt\Projekt_2._Versuch\Projekt_2._Versuch_Tweaking4all.ino\Projekt_2._Versuch_Tweaking4all.ino.ino:8:0:

C:\Users\Elektroniker.DESKTOP-7LBH8GJ\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.001

 # pragma message "FastLED version 3.003.001"

                     ^

(this error message is quiet common for me I'm having it every time I compile a programm even if it's working)


C:\Users\ELEKTR~1.DES\AppData\Local\Temp\ccqQJtne.ltrans1.ltrans.o: In function `loop':</b></i></p><p><i><b>Z:\Projekte, Bestellungen & Messungen\Projekte\Hauptprojekte\Projekt #9 Arduino\Versuch einbindung alle Projekt\Projekt\Projekt_2._Versuch\Projekt_2._Versuch_Tweaking4all.ino/Projekt_2._Versuch_Tweaking4all.ino.ino:71: undefined reference to `TwinkleRandom()'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Nano.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

Can u help me with that error message?


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2679
Topic starter  

The message:

# pragma message “FastLED version 3.003.001”

is actually not an error message (yes, I agree - why show it when it can confuse the user?) - so you can ignore that one.
It's just there so you can see which library version you're using.

The message:

ld returned 1 exit status

is a linker error - for some reason linking (ld) failed.
Maybe verbose output (File -> Preferences -> check "Show verbose output during: [ ] compilation".
Not sure if it will help.

Often this is related to the Arduino IDE - so also make sure you have the latest version of the Arduino IDE (which includes "ld").

As for the pins used: some pins can conflict.
I'm not an expert on this, but I know some pins are so called PWM pins (like PIN 6 and PINs 3, 5, 6, and 11) - see attached pictures (which can be quite confusing).
So my advice, since I'm not an expert either: start your project with 1 button. If it works OK, add another button. Keep doing this until you see it fail. For the last PIN added select another pin.

Another approach could be using the effect that you've tied to PIN 12 on a PIn you know that works. Just to make sure the effect does work.


   
ReplyQuote
(@trollo_meo)
New Member
Joined: 4 years ago
Posts: 4
 

Hello

Thank u for your help

I'm done now with my project and everything works fine even with the switches cause the functions for the RGB is an endless loop.

//LED-Matrix
//6 different modes can be switched with 6 switches
//11.11.2019
//Hier könnte Ihre Werbung stehen
#include "FastLED.h" //the FastLED-h Library getts included
#include <Adafruit_NeoPixel.h> //the Adafruit_NeoPixel.h Library getts included
#define NUM_LEDS 30 //the Variable NUM_LEDS is defined with 30
#define NUMPIXELS 30 //the amount of LED's is defined with 30
#define PIN 6
int aufblinkeninput = 12; //declaration of the pin 12 as aufblinkeninput
int fadeinput = 11; //declaration of the pin 11 as fadeinput
int fadeindermittetreffeninput = 10; //declaration of the pin 10 as fadeindermittetreffeninput
int funmodeinput = 9; //declaration of the pin 9 as funmodeinput
int geilerfadeinput = 8; //declaration of the pin 8 as geilerfadeinput
int rainbowfadeinput = 7; //declaration of the pin 7 as rainbowfadeinput
void TwinkleRandom(int, int, int, boolean); //declaration of the function TwinkleRandom
void addtoloop2(); //declaration of the function addtoloop2
void fade(); //declaration of the function fade
void addtoloop3(); //declaration of the function addtoloop3
void fader(); //declaration of the function fader
void rainbowCycle(uint8_t); //declaration of the function rainbowCycle
void setAll(byte, byte, byte); //declaration of the function setAll
void fadeall(int); //declaration of the function fadeall
void showStrip(); //declaration of the function showStrip
void brighten(); //declaration of the function brighten
void darken(); //declaration of the function darken



int i = 0;


//CRGB leds[NUM_LEDS];
CRGBArray<30> leds;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800); //the amount of LED's is 30

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //allows communication with a display -> here with a LED strip
  LEDS.addLeds<NEOPIXEL,PIN>(leds, NUM_LEDS);                               
  LEDS.addLeds<WS2811, PIN,BRG>(leds,NUM_LEDS); //out of the FastLED-library, does pinsettings
  strip.begin(); //declaration of the function strip.begin, starts the strip
  strip.show(); //strip.show light the LED's
  FastLED.addLeds<NEOPIXEL,6>(leds,NUM_LEDS);
  LEDS.setBrightness(255); //the brightness is setted to 255 (maximum)
  pinMode(aufblinkeninput, INPUT); //declaration of the pin aufblinkeninput as input
  pinMode(fadeinput, INPUT); //declaration of the pin fadeinput as input
  pinMode(fadeindermittetreffeninput, INPUT); //declaration of the pin fadeindermittetreffen as input
  pinMode(funmodeinput, INPUT); //declaration of the pin funmode as input
  pinMode(geilerfadeinput, INPUT); //declaration of the pin geilerfadeinput as input
  pinMode(rainbowfadeinput, INPUT); //declaration of the pin rainbowfadeinput as input
}
void loop() {
  //1. aufblinken 
if(digitalRead (aufblinkeninput) == HIGH) {                                                           
TwinkleRandom(1800,100,150,false); //if the pin aufblinkeninput is HIGH the function TwinkleRandom starts
}
//2. fade
if(digitalRead (fadeinput) == HIGH){                                                                   
  brighten(); //if the pin fadeinput is HIGH first the function brighten
  darken(); //second the function darken starts                                                                          
}
//3. fadeindermittetreffen
if(digitalRead (fadeindermittetreffeninput) == HIGH){
  addtoloop2(); //if the pin fadeindermittetreffeninput is HIGH the function addtoloop2 starts
}
//4. funmode
if(digitalRead (funmodeinput) == HIGH) {
  addtoloop3(); //if the pin funmodeinput is HIGH the function addtoloop3 starts
}
//5. geilerfade
if(digitalRead (geilerfadeinput) == HIGH) {
  fader(); //if the pin geilerfadeinput is HIGH the function fader starts
}
//6. rainbowfade
if(digitalRead (rainbowfadeinput) == HIGH) {
  rainbowfade(75); //if the pin rainbowfadeinput is HIGH the function rainbowCycle starts
}
}



//definitionen
//ALLES DAS NICHT IM LOOP IST!!!!
//1. aufblinken
void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) { //definition of the function TwinkleRandom
  if(digitalRead (aufblinkeninput) == HIGH){
  setAll(0,0,0);
  for (int i=0; i<Count; i++) {
    fadeall(fadespeed);
    setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) { 
      setAll(0,0,0); 
    }
  }
// delay(SpeedDelay);  
  
}
}

void setPixel(int Pixel, byte red, byte green, byte blue) { //definition of the function setPixel from the function TwinkleRandom
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) { //definition of the function setAll from the function TwinkleRandom
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}
void showStrip() { //definition of the function showStrip from the function TwinkleRandom
  FastLED.show();
}
void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds.nscale8(scale); } } //definition of the function fadeall from the function TwinkleRandom
  
//2. fade
void brighten() {
  if(digitalRead (fadeinput) == HIGH){
  uint16_t i, j;
  for (j = 0; j < 255; j++) { //j (brightness of the LED) getts brightened up to 255
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j); //definition of the color white, all of RGB-LED's have the same numeric
    }
    strip.show();
    delay(10); //10er delay, break of 10 miliseconds
    
  }
  //delay(1500);
}
}
// 255 to 0
void darken() {
  if(digitalRead (fadeinput) == HIGH){
  Serial.begin(9600);
  uint16_t i, j;
  for (j = 255; j > 0; j--) { //same function like brighten but the brightness getts increased
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j);
    }
    strip.show();
    delay(10);
    Serial.println(j);
  }
  delay(1500); //1500 milisecond delay (1.5 seconds)
}
}
//3.fadeindermittetreffen
void addtoloop2() {
  if(digitalRead (fadeindermittetreffeninput) == HIGH){
  static uint8_t hue;
  EVERY_N_MILLISECONDS(100){ //repeat the function every 100 miliseconds
    leds.fadeToBlackBy(180);
    if (i<NUM_LEDS/2){
      leds = CHSV(hue++,255,255);
      i++;
    }else{
      i=0;
    }
    leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0); //the amount of LED's getts bisect that the LED's meet in the middle
    FastLED.show();
  }
}
}
//4. funmode
void addtoloop3(){
  if(digitalRead (funmodeinput) == HIGH){
  
                                                                                           // Some example procedures showing how to display to the pixels:
  colorswitch(strip.Color(255, 0, 0), 50); //Red
  colorswitch(strip.Color(0, 255, 0), 50); //Green                                         
  colorswitch(strip.Color(0, 0, 255), 50); //Blue
                                                                                           // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); //White
  theaterChase(strip.Color(127, 0, 0), 50); //Red
  theaterChase(strip.Color( 0, 0, 127), 50); //Blue
  
  rainbow(20);
  rainbowCycle(20);                                                                       
  theaterChaseRainbow(50);
}
}
                                                                                           // Fill the dots one after the other with a color
void colorswitch(uint32_t c, uint8_t wait) { //the LED's brighten after each other in a definited color                               
  for(uint16_t i=0; i<strip.numPixels(); i++) { //i is the variable for the LED's
      strip.setPixelColor(i, c);
      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) {
  while(digitalRead (funmodeinput) == HIGH){
  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.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) { //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c); //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
      }
    }
  }
}
                                                                                        //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) {
  while(digitalRead (funmodeinput) == HIGH){
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); //the colors pulsate
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
}


//5.geilerfade
void fader(){
  if(digitalRead (geilerfadeinput) == HIGH){
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the brightness is setted to 255
    int r = 255; //the red LED is at maximum brightness -> the led is red
    int g = 0; //the green LED is dark
    int b = colorStep; //the blue LED brighten up until the red LED is covered
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) { //the brightness lowers 255 to 0
    int r = colorStep; //red getts increased with the variable colorstep and getts covered with the blue
    int g = 0; //the green LED is dark
    int b = 255; //red LED fades to blue
    for(int x = 0; x < NUM_LEDS; x++){                                            
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the LED getts brighter
    int r = 0; //the red LED is dark
    int g = colorStep; //the green LED brighten up until the blue LED is covered
    int b = 255; //the color fades from blue to green
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 0; //the red LED is dark
    int g = 255; //the blue LED is bright
    int b = colorStep; //the green LED darken
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {
    int r = colorStep; //the red LED brightens and covers the blue LED                                                
    int g = 255; //the blue LED is bright
    int b = 0; //the blue LED is dark  
    for(int x = 0; x < NUM_LEDS; x++){ //the amount of the brighten LED's counts up
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 255; //the red LED is bright
    int g = colorStep; //the green LED getts darker
    int b = 0; //the blue LED is dark                                                                  
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
  delay(10); 
  FastLED.show();
  }
}
}



//6. rainbowfade //definition not necessary it got defined before


void rainbowfade(uint8_t wait) {
  if(digitalRead (rainbowfadeinput) == HIGH){
  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, rotation(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
}
uint32_t rotation(byte WheelPos) {
  if(digitalRead (rainbowfadeinput) == HIGH){
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); //the colors pulsate
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
<font color="#333333" face="Monaco, Menlo, Consolas, Courier New, monospace"><span style="font-size: 12px; white-space: pre-wrap; background-color: rgb(248, 248, 248);">}</span></font>

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2679
Topic starter  

Awesome! Glad to hear you've got it to work! 


   
ReplyQuote
(@trollo_meo)
New Member
Joined: 4 years ago
Posts: 4
 

Nevermind

I had to do some changes in my code from my aufblinken function.

It's working now

thank u sooooo much for your help and the projects u did

I really like the website and how u interact with people who want to do sth with the LED stripe

Respect really

U did and still do an awesome job with supporting people when they have problems

here's my code:

the only thing u might have to change is an option to end the function cause now it's staying in the function if u selected it once.

But I'm sure that I and other people who want's to do sth similar will be able to programm that by themself.

//LED-Matrix
//6 different modes can be switched with 6 switches
//11.11.2019
#include "FastLED.h" //the FastLED-h Library getts included
#include <Adafruit_NeoPixel.h> //the Adafruit_NeoPixel.h Library getts included
#define NUM_LEDS 30 //the Variable NUM_LEDS is defined with 30
#define NUMPIXELS 30 //the amount of LED's is defined with 30
#define PIN 6
int aufblinkeninput = 12; //declaration of the pin 12 as aufblinkeninput
int fadeinput = 11; //declaration of the pin 11 as fadeinput
int fadeindermittetreffeninput = 10; //declaration of the pin 10 as fadeindermittetreffeninput
int funmodeinput = 9; //declaration of the pin 9 as funmodeinput
int geilerfadeinput = 8; //declaration of the pin 8 as geilerfadeinput
int rainbowfadeinput = 7; //declaration of the pin 7 as rainbowfadeinput
void TwinkleRandom(int, int, int, boolean); //declaration of the function TwinkleRandom
void addtoloop2(); //declaration of the function addtoloop2
void fade(); //declaration of the function fade
void addtoloop3(); //declaration of the function addtoloop3
void fader(); //declaration of the function fader
void rainbowCycle(uint8_t); //declaration of the function rainbowCycle
void setAll(byte, byte, byte); //declaration of the function setAll
void fadeall(int); //declaration of the function fadeall
void showStrip(); //declaration of the function showStrip
void brighten(); //declaration of the function brighten
void darken(); //declaration of the function darken



int i = 0;


//CRGB leds[NUM_LEDS];
CRGBArray<30> leds;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800); //the amount of LED's is 30

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //allows communication with a display -> here with a LED strip
  LEDS.addLeds<NEOPIXEL,PIN>(leds, NUM_LEDS);                               
  LEDS.addLeds<WS2811, PIN,BRG>(leds,NUM_LEDS); //out of the FastLED-library, does pinsettings
  strip.begin(); //declaration of the function strip.begin, starts the strip
  strip.show(); //strip.show light the LED's
  FastLED.addLeds<NEOPIXEL,6>(leds,NUM_LEDS);
  LEDS.setBrightness(255); //the brightness is setted to 255 (maximum)
  pinMode(aufblinkeninput, INPUT); //declaration of the pin aufblinkeninput as input
  pinMode(fadeinput, INPUT); //declaration of the pin fadeinput as input
  pinMode(fadeindermittetreffeninput, INPUT); //declaration of the pin fadeindermittetreffen as input
  pinMode(funmodeinput, INPUT); //declaration of the pin funmode as input
  pinMode(geilerfadeinput, INPUT); //declaration of the pin geilerfadeinput as input
  pinMode(rainbowfadeinput, INPUT); //declaration of the pin rainbowfadeinput as input
}
void loop() {
  //1. aufblinken 
if(digitalRead (aufblinkeninput) == HIGH) {                                                           
TwinkleRandom(1800,100,150,false); //if the pin aufblinkeninput is HIGH the function TwinkleRandom starts
}
//2. fade
if(digitalRead (fadeinput) == HIGH){                                                                   
  brighten(); //if the pin fadeinput is HIGH first the function brighten
  darken(); //second the function darken starts                                                                          
}
//3. fadeindermittetreffen
if(digitalRead (fadeindermittetreffeninput) == HIGH){
  addtoloop2(); //if the pin fadeindermittetreffeninput is HIGH the function addtoloop2 starts
}
//4. funmode
if(digitalRead (funmodeinput) == HIGH) {
  addtoloop3(); //if the pin funmodeinput is HIGH the function addtoloop3 starts
}
//5. geilerfade
if(digitalRead (geilerfadeinput) == HIGH) {
  fader(); //if the pin geilerfadeinput is HIGH the function fader starts
}
//6. rainbowfade
if(digitalRead (rainbowfadeinput) == HIGH) {
  rainbowCycle(75); //if the pin rainbowfadeinput is HIGH the function rainbowCycle starts
}
}



//definitionen
//ALLES DAS NICHT IM LOOP IST!!!!
//1. aufblinken
void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) { //definition of the function TwinkleRandom
  setAll(0,0,0);
  for (int i=0; i<Count; i++) {
    fadeall(fadespeed);
    setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) { 
      setAll(0,0,0); 
    }
  }
// delay(SpeedDelay);  
}

void setPixel(int Pixel, byte red, byte green, byte blue) { //definition of the function setPixel from the function TwinkleRandom
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) { //definition of the function setAll from the function TwinkleRandom
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}
void showStrip() { //definition of the function showStrip from the function TwinkleRandom
  FastLED.show();
}
void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds.nscale8(scale); } } //definition of the function fadeall from the function TwinkleRandom
  
//2. fade
void brighten() {
  uint16_t i, j;
  for (j = 0; j < 255; j++) { //j (brightness of the LED) getts brightened up to 255
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j); //definition of the color white, all of RGB-LED's have the same numeric
    }
    strip.show();
    delay(10); //10er delay, break of 10 miliseconds
    
  }
  //delay(1500);
}
// 255 to 0
void darken() {
  Serial.begin(9600);
  uint16_t i, j;
  for (j = 255; j > 0; j--) { //same function like brighten but the brightness getts increased
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, j, j, j);
    }
    strip.show();
    delay(10);
    Serial.println(j);
  }
  delay(1500); //1500 milisecond delay (1.5 seconds)
}
//3.fadeindermittetreffen
void addtoloop2() {
  static uint8_t hue;
  EVERY_N_MILLISECONDS(100){ //repeat the function every 100 miliseconds
    leds.fadeToBlackBy(180);
    if (i<NUM_LEDS/2){
      leds = CHSV(hue++,255,255);
      i++;
    }else{
      i=0;
    }
    leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0); //the amount of LED's getts bisect that the LED's meet in the middle
    FastLED.show();
  }
}
//4. funmode
void addtoloop3(){
                                                                                           // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); //Red
  colorWipe(strip.Color(0, 255, 0), 50); //Green                                         
  colorWipe(strip.Color(0, 0, 255), 50); //Blue
                                                                                           // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); //White
  theaterChase(strip.Color(127, 0, 0), 50); //Red
  theaterChase(strip.Color( 0, 0, 127), 50); //Blue
  
  rainbow(20);
  rainbowCycle(20);                                                                       
  theaterChaseRainbow(50);
}
                                                                                           // Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) { //the LED's brighten after each other in a definited color                               
  for(uint16_t i=0; i<strip.numPixels(); i++) { //i is the variable for the LED's
      strip.setPixelColor(i, c);
      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.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) { //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c); //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
      }
    }
  }
}
                                                                                        //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) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); //the colors pulsate
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}


//5.geilerfade
void fader(){
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the brightness is setted to 255
    int r = 255; //the red LED is at maximum brightness -> the led is red
    int g = 0; //the green LED is dark
    int b = colorStep; //the blue LED brighten up until the red LED is covered
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) { //the brightness lowers 255 to 0
    int r = colorStep; //red getts increased with the variable colorstep and getts covered with the blue
    int g = 0; //the green LED is dark
    int b = 255; //red LED fades to blue
    for(int x = 0; x < NUM_LEDS; x++){                                            
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) { //the LED getts brighter
    int r = 0; //the red LED is dark
    int g = colorStep; //the green LED brighten up until the blue LED is covered
    int b = 255; //the color fades from blue to green
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 0; //the red LED is dark
    int g = 255; //the blue LED is bright
    int b = colorStep; //the green LED darken
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {
    int r = colorStep; //the red LED brightens and covers the blue LED                                                
    int g = 255; //the blue LED is bright
    int b = 0; //the blue LED is dark  
    for(int x = 0; x < NUM_LEDS; x++){ //the amount of the brighten LED's counts up
      leds[x] = CRGB(r,g,b);
    }
    delay(10); 
    FastLED.show();
  }
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {
    int r = 255; //the red LED is bright
    int g = colorStep; //the green LED getts darker
    int b = 0; //the blue LED is dark                                                                  
    for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
    }
  delay(10); 
  FastLED.show();
  }
}

//6. rainbowfade //definition not necessary it got defined before

   
ReplyQuote
(@trollo_meo)
New Member
Joined: 4 years ago
Posts: 4
 

that sounds pretty obvious...

thank u for telling me

as mostly fixing a problem cause new problems

I'm using an Arduino Nano...

I tried to compile the programm but I'm having a error message....

(I've addet the error message)


   
ReplyQuote
Share: