Compare commits

...

2 Commits

Author SHA1 Message Date
078683b5b2 feat: Added button
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 4m8s
2023-10-26 15:31:07 +02:00
dc78ea7426 feat: Added button 2023-10-26 15:30:53 +02:00
2 changed files with 43 additions and 0 deletions

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) {

View File

@@ -15,9 +15,17 @@ struct Timings {
}
static TIMINGS: Mutex<Lazy<Timings>> = Mutex::new(Lazy::new(|| Timings { charging_start_delay: 1600, charging_delay: 450, charging_end_delay: 400 } ));
static PLAYING: Mutex<bool> = Mutex::new(false);
#[tauri::command]
pub fn start() {
let mut playing = PLAYING.lock().unwrap();
if *playing {
return;
} else {
*playing = true;
}
thread::spawn(move || {
println!("Starting animation...");
@@ -28,6 +36,9 @@ pub fn start() {
let _ = serial::write_serial(format!("SET_LIGHT:0;").as_str());
stage_one();
stage_two();
let mut playing = PLAYING.lock().unwrap();
*playing = false;
});
}