Compare commits
2 Commits
81edabee6e
...
078683b5b2
Author | SHA1 | Date | |
---|---|---|---|
078683b5b2 | |||
dc78ea7426 |
@@ -4,6 +4,7 @@ const int redPin = 4;
|
|||||||
const int greenPin = 5;
|
const int greenPin = 5;
|
||||||
const int bluePin = 13;
|
const int bluePin = 13;
|
||||||
const int whitePin = 14;
|
const int whitePin = 14;
|
||||||
|
const int btnPin = 18;
|
||||||
|
|
||||||
#define PIN_WS2812B 27
|
#define PIN_WS2812B 27
|
||||||
#define NUM_PIXELS 68
|
#define NUM_PIXELS 68
|
||||||
@@ -13,6 +14,12 @@ Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
|
|||||||
String inputCommand = "";
|
String inputCommand = "";
|
||||||
String inputColor = "";
|
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() {
|
void setup() {
|
||||||
ws2812b.begin();
|
ws2812b.begin();
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@@ -21,6 +28,7 @@ void setup() {
|
|||||||
pinMode(greenPin, OUTPUT);
|
pinMode(greenPin, OUTPUT);
|
||||||
pinMode(bluePin, OUTPUT);
|
pinMode(bluePin, OUTPUT);
|
||||||
pinMode(whitePin, OUTPUT);
|
pinMode(whitePin, OUTPUT);
|
||||||
|
pinMode(btnPin, INPUT);
|
||||||
|
|
||||||
analogWrite(redPin, 0);
|
analogWrite(redPin, 0);
|
||||||
analogWrite(greenPin, 0);
|
analogWrite(greenPin, 0);
|
||||||
@@ -60,6 +68,30 @@ void loop() {
|
|||||||
inputColor = ""; // Clear the inputColor string
|
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) {
|
void setLight(int brightnessValue) {
|
||||||
|
@@ -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 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]
|
#[tauri::command]
|
||||||
pub fn start() {
|
pub fn start() {
|
||||||
|
let mut playing = PLAYING.lock().unwrap();
|
||||||
|
|
||||||
|
if *playing {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
*playing = true;
|
||||||
|
}
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
println!("Starting animation...");
|
println!("Starting animation...");
|
||||||
|
|
||||||
@@ -28,6 +36,9 @@ pub fn start() {
|
|||||||
let _ = serial::write_serial(format!("SET_LIGHT:0;").as_str());
|
let _ = serial::write_serial(format!("SET_LIGHT:0;").as_str());
|
||||||
stage_one();
|
stage_one();
|
||||||
stage_two();
|
stage_two();
|
||||||
|
|
||||||
|
let mut playing = PLAYING.lock().unwrap();
|
||||||
|
*playing = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user