From e652b3115a5a98f5b83169392486215f3d27464c Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 01:27:44 +0530 Subject: [PATCH 01/21] Create Programmed External Keys.ino --- .../Programmed External Keys.ino | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/Programmable Buttons/Programmed External Keys.ino diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino new file mode 100644 index 0000000..ab43fee --- /dev/null +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -0,0 +1,68 @@ +/* + Programmed External Keys (Keyboard) + + For the Arduino Leonardo/any other arduino board with usb interface + + Reads a key from push button & acts as a CTRL+C (Copy). + Reads another key from push button & acts as a CTRL+V (Paste). + + + The circuit: + + The push button has 2 connectors. + We must connect gnd and the second will be connected to any I/O pin. + +connect register between (button & gnd)& then set pinMode() as INPUT. + + created 18 March 2020 + + by Prathamesh Sahasrabhojane (TheShubham99) + +*/ + +#include "Keyboard.h" + +const int btnPin[] = {2, 3, 4, 5}; +int pincount = 4; +int btnState[] = {0, 0, 0, 0}; +int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; + +long lastDebounceTime[] = {0, 0, 0, 0}; +long debounceDelay = 50; +void setup() { + for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + pinMode(btnPin[thisPin], INPUT); + digitalWrite(btnPin[thisPin], HIGH); + } + Keyboard.begin(); +} + +// Place the actions needed after pin press here +int outputAction(int currentButton) { + if (currentButton == 1) { + Keyboard.press(ctrlKey); + Keyboard.press('c'); + delay(100); + Keyboard.releaseAll(); + } + if (currentButton + 1 == 2) { + Keyboard.press(ctrlKey); + Keyboard.press('v'); + delay(100); + Keyboard.releaseAll(); + } +} +void loop() { + for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + btnState[thisPin] = digitalRead(btnPin[thisPin]); + + if ((btnState[thisPin] != prevbtnState[thisPin]) && (btnState[thisPin] == HIGH)) { + if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { + outputAction(thisPin); + lastDebounceTime[thisPin] = millis(); + } + } + + prevbtnState[thisPin] = btnState[thisPin]; + } +} \ No newline at end of file From d34599723eda577aa7ab949371baeca57341b8fc Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 18:50:50 +0530 Subject: [PATCH 02/21] Apply suggestions from code review Formating Done Co-Authored-By: per1234 --- .../Programmed External Keys.ino | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index ab43fee..ab40d78 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -1,26 +1,20 @@ /* Programmed External Keys (Keyboard) - For the Arduino Leonardo/any other arduino board with usb interface + For native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due) - Reads a key from push button & acts as a CTRL+C (Copy). - Reads another key from push button & acts as a CTRL+V (Paste). + When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated. + When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated. - The circuit: - - The push button has 2 connectors. - We must connect gnd and the second will be connected to any I/O pin. - -connect register between (button & gnd)& then set pinMode() as INPUT. + The push buttons have 2 connectors. + Connect one to GND and the other to the I/O pin defined in the btnPin array. created 18 March 2020 - by Prathamesh Sahasrabhojane (TheShubham99) - */ -#include "Keyboard.h" +#include const int btnPin[] = {2, 3, 4, 5}; int pincount = 4; @@ -65,4 +59,4 @@ void loop() { prevbtnState[thisPin] = btnState[thisPin]; } -} \ No newline at end of file +} From f9f53f81a9500a670e6a0d5194c9911af49bc4db Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:01:48 +0530 Subject: [PATCH 03/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index ab40d78..a27799f 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -32,7 +32,7 @@ void setup() { } // Place the actions needed after pin press here -int outputAction(int currentButton) { +void outputAction(int currentButton) { if (currentButton == 1) { Keyboard.press(ctrlKey); Keyboard.press('c'); From 6132af0ef9dde78db89093ef843bae1f2d72769f Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:02:14 +0530 Subject: [PATCH 04/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index a27799f..3373a15 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -21,7 +21,7 @@ int pincount = 4; int btnState[] = {0, 0, 0, 0}; int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; -long lastDebounceTime[] = {0, 0, 0, 0}; +unsigned long lastDebounceTime[] = {0, 0, 0, 0}; long debounceDelay = 50; void setup() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { From 623a9f134dca0a78813a07bf61fada22569bd69f Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:02:47 +0530 Subject: [PATCH 05/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index 3373a15..f0440c9 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -22,7 +22,7 @@ int btnState[] = {0, 0, 0, 0}; int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0, 0, 0}; -long debounceDelay = 50; +unsigned long debounceDelay = 50; void setup() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { pinMode(btnPin[thisPin], INPUT); From d6e11f33d8320be9ed77972ef4e7000bfd9caa3e Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:04:46 +0530 Subject: [PATCH 06/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index f0440c9..fa9240c 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -23,6 +23,7 @@ int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0, 0, 0}; unsigned long debounceDelay = 50; + void setup() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { pinMode(btnPin[thisPin], INPUT); From 81773c3622289ed70b7f5e02aba75a9825b57565 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:06:29 +0530 Subject: [PATCH 07/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index fa9240c..c4741e6 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -47,6 +47,7 @@ void outputAction(int currentButton) { Keyboard.releaseAll(); } } + void loop() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); From e4069195ba595b30568b8c2b4461bd39cfdd4dcd Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:07:54 +0530 Subject: [PATCH 08/21] Apply suggestions from code review Control structures simplified Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index c4741e6..d0cf7fe 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -40,8 +40,8 @@ void outputAction(int currentButton) { delay(100); Keyboard.releaseAll(); } - if (currentButton + 1 == 2) { - Keyboard.press(ctrlKey); + else if (currentButton == 2) { + Keyboard.press(KEY_LEFT_CTRL); Keyboard.press('v'); delay(100); Keyboard.releaseAll(); From d162f6ccf53c32f055d1f519baccbec91c956019 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:08:35 +0530 Subject: [PATCH 09/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index d0cf7fe..6d207a6 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -18,7 +18,7 @@ const int btnPin[] = {2, 3, 4, 5}; int pincount = 4; -int btnState[] = {0, 0, 0, 0}; +int btnState[pincount]; int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0, 0, 0}; From a6750917f1c8062d0d3bb62513eb9dd0b74d8039 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:09:10 +0530 Subject: [PATCH 10/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index 6d207a6..4fce5aa 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -26,8 +26,7 @@ unsigned long debounceDelay = 50; void setup() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { - pinMode(btnPin[thisPin], INPUT); - digitalWrite(btnPin[thisPin], HIGH); + pinMode(btnPin[thisPin], INPUT_PULLUP); } Keyboard.begin(); } From 0705b2396d6d8d007f78ea33c98b08353e7000bf Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:09:51 +0530 Subject: [PATCH 11/21] Update examples/Programmable Buttons/Programmed External Keys.ino Co-Authored-By: per1234 --- examples/Programmable Buttons/Programmed External Keys.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index 4fce5aa..19e43ac 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -34,7 +34,7 @@ void setup() { // Place the actions needed after pin press here void outputAction(int currentButton) { if (currentButton == 1) { - Keyboard.press(ctrlKey); + Keyboard.press(KEY_LEFT_CTRL); Keyboard.press('c'); delay(100); Keyboard.releaseAll(); From 0bbeb9b53fd4b62b1dd14e4def7aad60e94b666c Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:13:50 +0530 Subject: [PATCH 12/21] Code Readability & Optimization --- .../Programmed External Keys.ino | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino index 19e43ac..4c41f16 100644 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ b/examples/Programmable Buttons/Programmed External Keys.ino @@ -1,13 +1,13 @@ /* Programmed External Keys (Keyboard) - + For native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due) - + When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated. When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated. - + The circuit: - The push buttons have 2 connectors. + The push buttons have 2 connectors. Connect one to GND and the other to the I/O pin defined in the btnPin array. created 18 March 2020 @@ -17,15 +17,15 @@ #include const int btnPin[] = {2, 3, 4, 5}; -int pincount = 4; -int btnState[pincount]; +int pinCount = 4; +int btnState[pinCount]; int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0, 0, 0}; unsigned long debounceDelay = 50; void setup() { - for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { pinMode(btnPin[thisPin], INPUT_PULLUP); } Keyboard.begin(); @@ -33,22 +33,22 @@ void setup() { // Place the actions needed after pin press here void outputAction(int currentButton) { - if (currentButton == 1) { - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press('c'); - delay(100); - Keyboard.releaseAll(); - } - else if (currentButton == 2) { - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press('v'); - delay(100); - Keyboard.releaseAll(); - } + if (currentButton == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('c'); + delay(100); + Keyboard.releaseAll(); + } + else if (currentButton == 2) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('v'); + delay(100); + Keyboard.releaseAll(); + } } void loop() { - for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); if ((btnState[thisPin] != prevbtnState[thisPin]) && (btnState[thisPin] == HIGH)) { From ae4b8ac93342efac4ac5131b768301aea80646ea Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:23:02 +0530 Subject: [PATCH 13/21] Updating ProgrammableButtons Example for native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due) - When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated. -When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated. --- .../ProgrammableButtons.ino | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/ProgrammableButtons/ProgrammableButtons.ino diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino new file mode 100644 index 0000000..aa30afa --- /dev/null +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -0,0 +1,63 @@ +/* + Programmed External Keys (Keyboard) + + For native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due) + + When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated. + When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated. + + The circuit: + The push buttons have 2 connectors. + Connect one to GND and the other to the I/O pin defined in the btnPin array. + + created 18 March 2020 + by Prathamesh Sahasrabhojane (TheShubham99) +*/ + +#include + +const int btnPin[] = {2, 3, 4, 5}; +int pincount = 2; +int btnState[pincount]; +int prevBtnState[] = {HIGH, HIGH, HIGH, HIGH}; + +unsigned long lastDebounceTime[] = {0, 0, 0, 0}; +unsigned long debounceDelay = 50; + +void setup() { + for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + pinMode(btnPin[thisPin], INPUT_PULLUP); + } + Keyboard.begin(); +} + +// Place the actions needed after pin press here +void outputAction(int currentButton) { + if (currentButton == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('c'); + delay(100); + Keyboard.releaseAll(); + } + else if (currentButton == 2) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('v'); + delay(100); + Keyboard.releaseAll(); + } +} + +void loop() { + for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + btnState[thisPin] = digitalRead(btnPin[thisPin]); + + if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == HIGH)) { + if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { + outputAction(thisPin); + lastDebounceTime[thisPin] = millis(); + } + } + + prevBtnState[thisPin] = btnState[thisPin]; + } +} From a0f90f49f147cf5301f4272b4ee0af4b1ea22172 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Wed, 18 Mar 2020 19:30:15 +0530 Subject: [PATCH 14/21] Delete Programmed External Keys.ino --- .../Programmed External Keys.ino | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 examples/Programmable Buttons/Programmed External Keys.ino diff --git a/examples/Programmable Buttons/Programmed External Keys.ino b/examples/Programmable Buttons/Programmed External Keys.ino deleted file mode 100644 index 4c41f16..0000000 --- a/examples/Programmable Buttons/Programmed External Keys.ino +++ /dev/null @@ -1,63 +0,0 @@ -/* - Programmed External Keys (Keyboard) - - For native USB Arduino boards (e.g., Leonardo, Micro, MKR, Nano 33 IoT, Zero, Due) - - When the first button is pressed, the Ctrl + C keyboard shortcut (copy) is emulated. - When the second button is pressed, the Ctrl + V keyboard shortcut (paste) is emulated. - - The circuit: - The push buttons have 2 connectors. - Connect one to GND and the other to the I/O pin defined in the btnPin array. - - created 18 March 2020 - by Prathamesh Sahasrabhojane (TheShubham99) -*/ - -#include - -const int btnPin[] = {2, 3, 4, 5}; -int pinCount = 4; -int btnState[pinCount]; -int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; - -unsigned long lastDebounceTime[] = {0, 0, 0, 0}; -unsigned long debounceDelay = 50; - -void setup() { - for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { - pinMode(btnPin[thisPin], INPUT_PULLUP); - } - Keyboard.begin(); -} - -// Place the actions needed after pin press here -void outputAction(int currentButton) { - if (currentButton == 1) { - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press('c'); - delay(100); - Keyboard.releaseAll(); - } - else if (currentButton == 2) { - Keyboard.press(KEY_LEFT_CTRL); - Keyboard.press('v'); - delay(100); - Keyboard.releaseAll(); - } -} - -void loop() { - for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { - btnState[thisPin] = digitalRead(btnPin[thisPin]); - - if ((btnState[thisPin] != prevbtnState[thisPin]) && (btnState[thisPin] == HIGH)) { - if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { - outputAction(thisPin); - lastDebounceTime[thisPin] = millis(); - } - } - - prevbtnState[thisPin] = btnState[thisPin]; - } -} From 5b8575f66a5924611e25a6cec01c0eb4b18ff27f Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Thu, 19 Mar 2020 14:44:44 +0530 Subject: [PATCH 15/21] Update examples/ProgrammableButtons/ProgrammableButtons.ino Co-Authored-By: per1234 --- examples/ProgrammableButtons/ProgrammableButtons.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index aa30afa..446ebe8 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -51,7 +51,7 @@ void loop() { for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); - if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == HIGH)) { + if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == LOW)) { if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { outputAction(thisPin); lastDebounceTime[thisPin] = millis(); From 4147bd713fdb9310560dc7334bd6c7da1c5e2139 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Thu, 19 Mar 2020 15:07:30 +0530 Subject: [PATCH 16/21] Update ProgrammableButtons.ino --- examples/ProgrammableButtons/ProgrammableButtons.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index 446ebe8..3eca547 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -16,12 +16,12 @@ #include -const int btnPin[] = {2, 3, 4, 5}; -int pincount = 2; +const int btnPin[] = {2, 3}; +const int pincount = 2; int btnState[pincount]; -int prevBtnState[] = {HIGH, HIGH, HIGH, HIGH}; +int prevBtnState[] = {HIGH, HIGH}; -unsigned long lastDebounceTime[] = {0, 0, 0, 0}; +unsigned long lastDebounceTime[] = {0, 0}; unsigned long debounceDelay = 50; void setup() { @@ -61,3 +61,4 @@ void loop() { prevBtnState[thisPin] = btnState[thisPin]; } } + From b2183abd2e307950e3a8901735b8b8952ee2e446 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Thu, 19 Mar 2020 15:17:09 +0530 Subject: [PATCH 17/21] Update ProgrammableButtons.ino --- examples/ProgrammableButtons/ProgrammableButtons.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index 3eca547..4ff30d2 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -17,15 +17,15 @@ #include const int btnPin[] = {2, 3}; -const int pincount = 2; -int btnState[pincount]; +const int pinCount = 2; +int btnState[pinCount]; int prevBtnState[] = {HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0}; unsigned long debounceDelay = 50; void setup() { - for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { pinMode(btnPin[thisPin], INPUT_PULLUP); } Keyboard.begin(); @@ -33,13 +33,13 @@ void setup() { // Place the actions needed after pin press here void outputAction(int currentButton) { - if (currentButton == 1) { + if (currentButton == 0) { Keyboard.press(KEY_LEFT_CTRL); Keyboard.press('c'); delay(100); Keyboard.releaseAll(); } - else if (currentButton == 2) { + else if (currentButton == 1) { Keyboard.press(KEY_LEFT_CTRL); Keyboard.press('v'); delay(100); @@ -48,7 +48,7 @@ void outputAction(int currentButton) { } void loop() { - for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == LOW)) { From bfb8ff1c4bb4714acfdb2605aaaf0a03871a2612 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Thu, 19 Mar 2020 15:29:55 +0530 Subject: [PATCH 18/21] Update ProgrammableButtons.ino Making Trigger when pinstate is HIGH. --- examples/ProgrammableButtons/ProgrammableButtons.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index 4ff30d2..5b68f30 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -19,7 +19,7 @@ const int btnPin[] = {2, 3}; const int pinCount = 2; int btnState[pinCount]; -int prevBtnState[] = {HIGH, HIGH}; +int prevBtnState[] = {HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0}; unsigned long debounceDelay = 50; @@ -51,7 +51,7 @@ void loop() { for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); - if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == LOW)) { + if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == HIGH)) { if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { outputAction(thisPin); lastDebounceTime[thisPin] = millis(); From 5282143d852dc8769268bbdc8e16d688224db3f9 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Fri, 20 Mar 2020 16:11:50 +0530 Subject: [PATCH 19/21] Update ProgrammableButtons.ino --- examples/ProgrammableButtons/ProgrammableButtons.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index 5b68f30..b2d10a5 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -51,7 +51,7 @@ void loop() { for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { btnState[thisPin] = digitalRead(btnPin[thisPin]); - if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == HIGH)) { + if ((btnState[thisPin] != prevBtnState[thisPin]) && (btnState[thisPin] == LOW)) { if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { outputAction(thisPin); lastDebounceTime[thisPin] = millis(); From f91d0a400c01d9a78b9b718be9868d2b1be46646 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Fri, 20 Mar 2020 19:09:45 +0530 Subject: [PATCH 20/21] Update examples/ProgrammableButtons/ProgrammableButtons.ino Co-Authored-By: per1234 --- examples/ProgrammableButtons/ProgrammableButtons.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index b2d10a5..3603fd2 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -32,7 +32,7 @@ void setup() { } // Place the actions needed after pin press here -void outputAction(int currentButton) { +void outputAction(const int currentButton) { if (currentButton == 0) { Keyboard.press(KEY_LEFT_CTRL); Keyboard.press('c'); @@ -61,4 +61,3 @@ void loop() { prevBtnState[thisPin] = btnState[thisPin]; } } - From e3aaa42685b2db2d695018c707dceda40f25bf96 Mon Sep 17 00:00:00 2001 From: Prathamesh Sahasrabhojane Date: Fri, 20 Mar 2020 19:10:17 +0530 Subject: [PATCH 21/21] Update examples/ProgrammableButtons/ProgrammableButtons.ino Co-Authored-By: per1234 --- examples/ProgrammableButtons/ProgrammableButtons.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ProgrammableButtons/ProgrammableButtons.ino b/examples/ProgrammableButtons/ProgrammableButtons.ino index 3603fd2..a060db4 100644 --- a/examples/ProgrammableButtons/ProgrammableButtons.ino +++ b/examples/ProgrammableButtons/ProgrammableButtons.ino @@ -22,7 +22,7 @@ int btnState[pinCount]; int prevBtnState[] = {HIGH, HIGH}; unsigned long lastDebounceTime[] = {0, 0}; -unsigned long debounceDelay = 50; +const unsigned long debounceDelay = 50; void setup() { for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {