/*
Acryl Sign
by smi1100 - 12/09/2022
pins:
LED: 6
Buttons: 8, 9
libraries:
- Adafruit_NeoPixel.h
*/
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6 // Which pin on the Arduino is connected to the NeoPixels?
#define LED_COUNT 8 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
const int buttonPin_front = 8;
boolean oldButtonState_front = HIGH;
boolean newButtonState_front;
int strip_color_front = 1;
const int buttonPin_back = 9;
boolean oldButtonState_back = HIGH;
boolean newButtonState_back;
int strip_color_back = 1;
void setup()
{
Serial.begin(9600);
strip.begin();
strip.show();
strip.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
pinMode(buttonPin_front, INPUT_PULLUP);
pinMode(buttonPin_back, INPUT_PULLUP);
Serial.println("Setup complete");
Serial.println("");
delay(500);
}
void loop()
{
newButtonState_front = digitalRead(buttonPin_front);
if((newButtonState_front == LOW) && (oldButtonState_front == HIGH)) // Button not pressed = LOW
{
delay(20); // Short delay to debounce button.
newButtonState_front = digitalRead(buttonPin_front); // Check if button is still low after debounce.
if(newButtonState_front == LOW) // Yes, still low
// einschalten (new = 0, old = 1)
// zu Beginn wird die if Schleife aktiviert und die erste Farbe angezeigt
// am Ende der Schleife old = new (new = 0, old = 0)
// Knopf gedrckt (if Schleife nicht durchlaufen (new = 1, old = 0)
// am Ende der Schleife old = new (new = 1, old = 1) - if Schleife nicht durchlaufen
// Knopf loslassen(new = 0, old = 1) -> If Schleife durchlaufen, Farbe ndert sich
{
if(strip_color_front > 8) strip_color_front = 1;
Serial.print("strip color front number: "); Serial.println(strip_color_front);
switch (strip_color_front)
{
case 1:
Serial.println("Strip color front RED");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 2:
Serial.println("Strip color front GREEN");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 0, 255, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 3:
Serial.println("Strip color front BLUE");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 0, 0, 255); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 4:
Serial.println("Strip color front WHITE");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 255, 255); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 5:
Serial.println("Strip color front PINK");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 20, 147); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 6:
Serial.println("Strip color front YELLOW");
Serial.println("");
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 215,0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 7:
Serial.println("Strip color front rainbow");
Serial.println("");
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256)
{
strip.rainbow(firstPixelHue);
strip.show();
Serial.print("firstPixelHue: ");Serial.println(firstPixelHue);
delay(10);
if (firstPixelHue == 327168) firstPixelHue = 0;
newButtonState_front = digitalRead(buttonPin_front);
newButtonState_back = digitalRead(buttonPin_back);
if(newButtonState_front == HIGH || newButtonState_back == HIGH)
{
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
strip_color_back = 1;
break;
}
}
break;
case 8:
Serial.println("Strip color front color wipe");
Serial.println("");
int stopper = 0;
while (stopper == 0)
{
Serial.print("Stopper: ");Serial.println(stopper);
for(int i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, 255, 0, 0);
strip.show();
newButtonState_front = digitalRead(buttonPin_front);
newButtonState_back = digitalRead(buttonPin_back);
if(newButtonState_front == HIGH || newButtonState_back == HIGH)
{
stopper = 1;
break;
}
delay(200);
}
for(int i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, 0, 255, 0);
strip.show();
newButtonState_front = digitalRead(buttonPin_front);
newButtonState_back = digitalRead(buttonPin_back);
if(newButtonState_front == HIGH || newButtonState_back == HIGH)
{
stopper = 1;
break;
}
delay(200);
}
for(int i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, 0, 0, 255);
strip.show();
newButtonState_front = digitalRead(buttonPin_front);
newButtonState_back = digitalRead(buttonPin_back);
if(newButtonState_front == HIGH || newButtonState_back == HIGH)
{
stopper = 1;
break;
}
delay(200);
}
}
for (int i = 0; i <= 3;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
strip_color_back = 1;
break;
} // end of switch
strip_color_front++;
}
}
oldButtonState_front = newButtonState_front;
newButtonState_back = digitalRead(buttonPin_back);
if((newButtonState_back == LOW) && (oldButtonState_back == HIGH))
{
delay(20);
newButtonState_back = digitalRead(buttonPin_back);
if(newButtonState_back == LOW)
{
if(strip_color_back > 6) strip_color_back = 1;
Serial.print("strip color back number: "); Serial.println(strip_color_back);
switch (strip_color_back)
{
case 1:
Serial.println("Strip color back RED");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 0, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 2:
Serial.println("Strip color back GREEN");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 0, 255, 0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 3:
Serial.println("Strip color back BLUE");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 0, 0, 255); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 4:
Serial.println("Strip color back WHITE");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 255, 255); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 5:
Serial.println("Strip color back PINK");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 20, 147); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
case 6:
Serial.println("Strip color back YELLOW");
Serial.println("");
for (int i = 4; i <= 7;i++)
{
strip.setPixelColor(i, 255, 215,0); //strip.setPixelColor(n, red, green, blue);
}
strip.show();
break;
}
strip_color_back++;
}
}
oldButtonState_back = newButtonState_back;
}
void colorWipe(uint32_t color, int wait)
{
for(int i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
Comments