From f4905feb815ae6505b360e65b699aa1902f7995b Mon Sep 17 00:00:00 2001 From: mlackner Date: Mon, 25 Aug 2025 21:38:55 +0200 Subject: [PATCH] add interrupt --- espkeyboard.ino | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/espkeyboard.ino b/espkeyboard.ino index 40fbcfb..89431de 100644 --- a/espkeyboard.ino +++ b/espkeyboard.ino @@ -3,8 +3,19 @@ BleKeyboard bleKeyboard; +const int SW1 = 4; +const int SW2 = 3; +const int LED_PIN = 5; +volatile byte state = LOW; void setup() { + + pinMode(LED_PIN, OUTPUT); + pinMode(SW1, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(SW1), setledhigh, FALLING); + pinMode(SW2, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(SW2), setledlow, FALLING); + Serial.begin(115200); Serial.println("Starting BLE work!"); bleKeyboard.begin(); @@ -12,6 +23,8 @@ void setup() { void loop() { if(bleKeyboard.isConnected()) { + + /* Serial.println("Sending 'Hello world'..."); bleKeyboard.print("Hello world"); @@ -24,7 +37,7 @@ void loop() { Serial.println("Sending Play/Pause media key..."); bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE); - + */ delay(1000); // @@ -43,3 +56,22 @@ void loop() { Serial.println("Waiting 5 seconds..."); delay(5000); } + + +void setledhigh(){ + digitalWrite(LED_PIN, HIGH); + if(bleKeyboard.isConnected()) { + bleKeyboard.write(KEY_MEDIA_VOLUME_UP); + bleKeyboard.print("4"); + } + Serial.println("Pressed pin 4"); +} + +void setledlow(){ + digitalWrite(LED_PIN, LOW); + if(bleKeyboard.isConnected()) { + bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN); + bleKeyboard.print("3"); + } + Serial.println("Pressed pin 3"); +}