/*
Author: Gregor Mausser
Titel: Home LED
Technical Data:
ESP32 C3
*/
//include NeoPixel Bibliothek
#include <Adafruit_NeoPixel.h>
const int LEDStripPin1 = 1; //Pin for the LED-Strip
int LEDPixels = 40; //Number of pixels the LED-Stripe has.
//If you have two or more LED-strips chained together you have to add the number of pixels.
const int ButtonPin = 2; //Pin for the Button
int mode = 0; //in which mode the LED-strip is
bool lastReading = HIGH;
bool stableState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 30;
//create NeoPixel object
Adafruit_NeoPixel strip(LEDPixels, LEDStripPin1, NEO_GRB + NEO_KHZ800); //Number of Pixels, Datapin, colorformate + signalspeed
//uint8_t and int8_t are 8 Bit numbers without sign (-/+)
uint8_t brightness = 0; //brightness 0-255
int8_t direction = 1; //brighter = 1, darker = -1
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
pinMode(ButtonPin, INPUT_PULLUP); //defines if the Button is an input or an output
strip.begin(); //initializeing LED-strip
strip.show(); //turns off all LEDs
}
void loop() {
bool reading = digitalRead(ButtonPin);
if (reading != lastReading) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != stableState) {
stableState = reading;
if (stableState == LOW) {
mode++;
Serial.println(mode);
/*
Code hier einfügen
Code hier einfügen
Code hier einfügen
*/
}
}
}
lastReading = reading;
switch(mode) {
case 1:
brightness += direction * 3;
if (brightness >= 255) {
Serial.println("Welcome");
}
for (int i = 0; i < LEDPixels; i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
delay(30);
break;
case 2:
for (int i = 0; i < LEDPixels; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
}
strip.show();
delay(30);
break;
case 3:
for (int i = 0; i < LEDPixels; i++) {
strip.setPixelColor(i, strip.Color(0, 255, 0));
}
strip.show();
delay(30);
break;
case 4:
for (int i = 0; i < LEDPixels; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 255));
}
strip.show();
delay(30);
break;
/*
default:
mode = 4;
Serial.println("Error");
*/
}
}