-
Notifications
You must be signed in to change notification settings - Fork 519
Description
Hi there
can anyone help me correct this code please?
as i am getting the following error:
C:\Users\steve\Downloads\sketch_mar17a\sketch_mar17a.ino: In function 'void loop()':
C:\Users\steve\Downloads\sketch_mar17a\sketch_mar17a.ino:16:43: error: expected primary-expression before ';' token
16 | static unsigned long buttonPressStart = ; // Initialize to
| ^
exit status 1
Compilation error: expected primary-expression before ';' token
#include <BleKeyboard.h>
BleKeyboard bleKeyboard("ESP32-Keyboard2", "Me", 100);
#define BUTTON_PIN 4
#define LONG_PRESS_DURATION 100 // Duration for long press in milliseconds
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("Starting BLE work!");
bleKeyboard.begin();
}
void loop() {
static unsigned long buttonPressStart = ; // Initialize to
static bool buttonPressed = false;
// Read the button state
bool buttonState = digitalRead(BUTTON_PIN) == LOW;
if (buttonState && !buttonPressed) {
// Button is pressed
buttonPressed = true;
buttonPressStart = millis(); // Record the time when the button was pressed
}
else if (!buttonState && buttonPressed) {
// Button is released
buttonPressed = false;
unsigned long pressDuration = millis() - buttonPressStart; // Calculate press duration
if (pressDuration >= LONG_PRESS_DURATION) {
// Long press detected
Serial.println("Rewind 10 seconds");
bleKeyboard.write(KEY_LEFT_ARROW); // Simulating rewind
} else {
// Short press detected
Serial.println("Play/Pause");
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE); // Simulating play/pause
}
}
delay(50); // Small delay to debounce
}
UPDATE
I NOW HAVE THIS CODE WORKING FOR 2 SWITCHES (Written by ai!)
#include <BleKeyboard.h>
BleKeyboard bleKeyboard;
const int pausePlayButton = 14; // GPIO pin for Pause/Play button
const int rewindButton = 27; // GPIO pin for Rewind button
void setup() {
Serial.begin(115200);
pinMode(pausePlayButton, INPUT_PULLUP); // Set button pin as input with pull-up
pinMode(rewindButton, INPUT_PULLUP); // Set button pin as input with pull-up
bleKeyboard.begin();
}
void loop() {
if (digitalRead(pausePlayButton) == LOW) { // Check if Pause/Play button is pressed
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE); // Send Play/Pause command
delay(200); // Debounce delay
}
if (digitalRead(rewindButton) == LOW) { // Check if Rewind button is pressed
bleKeyboard.write(KEY_LEFT_ARROW); // Send Previous Track command
delay(200); // Debounce delay
}
}