-
Notifications
You must be signed in to change notification settings - Fork 165
feat: Add Programmed External Keys. #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheShubham99
wants to merge
21
commits into
arduino-libraries:master
Choose a base branch
from
TheShubham99:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e652b31
Create Programmed External Keys.ino
TheShubham99 d345997
Apply suggestions from code review
TheShubham99 f9f53f8
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 6132af0
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 623a9f1
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 d6e11f3
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 81773c3
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 e406919
Apply suggestions from code review
TheShubham99 d162f6c
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 a675091
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 0705b23
Update examples/Programmable Buttons/Programmed External Keys.ino
TheShubham99 0bbeb9b
Code Readability & Optimization
TheShubham99 ae4b8ac
Updating ProgrammableButtons
TheShubham99 a0f90f4
Delete Programmed External Keys.ino
TheShubham99 5b8575f
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 4147bd7
Update ProgrammableButtons.ino
TheShubham99 b2183ab
Update ProgrammableButtons.ino
TheShubham99 bfb8ff1
Update ProgrammableButtons.ino
TheShubham99 5282143
Update ProgrammableButtons.ino
TheShubham99 f91d0a4
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 e3aaa42
Update examples/ProgrammableButtons/ProgrammableButtons.ino
TheShubham99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Keyboard.h> | ||
|
||
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) { | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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] == LOW)) { | ||
if ((millis() - lastDebounceTime[thisPin]) > debounceDelay) { | ||
outputAction(thisPin); | ||
lastDebounceTime[thisPin] = millis(); | ||
} | ||
} | ||
|
||
prevBtnState[thisPin] = btnState[thisPin]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.