feat: Added button
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 4m8s

This commit is contained in:
Xeovalyte 2023-10-26 15:31:07 +02:00
parent dc78ea7426
commit 078683b5b2

View File

@ -4,6 +4,7 @@ const int redPin = 4;
const int greenPin = 5;
const int bluePin = 13;
const int whitePin = 14;
const int btnPin = 18;
#define PIN_WS2812B 27
#define NUM_PIXELS 68
@ -13,6 +14,12 @@ Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
String inputCommand = "";
String inputColor = "";
int buttonState = 0;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50;
void setup() {
ws2812b.begin();
Serial.begin(9600);
@ -21,6 +28,7 @@ void setup() {
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(btnPin, INPUT);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
@ -60,6 +68,30 @@ void loop() {
inputColor = ""; // Clear the inputColor string
}
}
int reading = digitalRead(btnPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
Serial.write("1");
}
}
}
lastButtonState = reading;
}
void setLight(int brightnessValue) {