add interrupt
This commit is contained in:
parent
b75f7e2ddc
commit
f4905feb81
@ -3,8 +3,19 @@
|
|||||||
|
|
||||||
|
|
||||||
BleKeyboard bleKeyboard;
|
BleKeyboard bleKeyboard;
|
||||||
|
const int SW1 = 4;
|
||||||
|
const int SW2 = 3;
|
||||||
|
const int LED_PIN = 5;
|
||||||
|
volatile byte state = LOW;
|
||||||
|
|
||||||
void setup() {
|
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.begin(115200);
|
||||||
Serial.println("Starting BLE work!");
|
Serial.println("Starting BLE work!");
|
||||||
bleKeyboard.begin();
|
bleKeyboard.begin();
|
||||||
@ -12,6 +23,8 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(bleKeyboard.isConnected()) {
|
if(bleKeyboard.isConnected()) {
|
||||||
|
|
||||||
|
/*
|
||||||
Serial.println("Sending 'Hello world'...");
|
Serial.println("Sending 'Hello world'...");
|
||||||
bleKeyboard.print("Hello world");
|
bleKeyboard.print("Hello world");
|
||||||
|
|
||||||
@ -24,7 +37,7 @@ void loop() {
|
|||||||
|
|
||||||
Serial.println("Sending Play/Pause media key...");
|
Serial.println("Sending Play/Pause media key...");
|
||||||
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
|
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
|
||||||
|
*/
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -43,3 +56,22 @@ void loop() {
|
|||||||
Serial.println("Waiting 5 seconds...");
|
Serial.println("Waiting 5 seconds...");
|
||||||
delay(5000);
|
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");
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user