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[i].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[i] = 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>