-
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 1 commit
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
68 changes: 68 additions & 0 deletions
68
examples/Programmable Buttons/Programmed External Keys.ino
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,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). | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
The circuit: | ||
|
||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The push button has 2 connectors. | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
We must connect gnd and the second will be connected to any I/O pin. | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
connect register between (button & gnd)& then set pinMode() as INPUT. | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
created 18 March 2020 | ||
|
||
by Prathamesh Sahasrabhojane (TheShubham99) | ||
|
||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
#include "Keyboard.h" | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const int btnPin[] = {2, 3, 4, 5}; | ||
per1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int pincount = 4; | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int btnState[] = {0, 0, 0, 0}; | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int prevbtnState[] = {HIGH, HIGH, HIGH, HIGH}; | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
long lastDebounceTime[] = {0, 0, 0, 0}; | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
long debounceDelay = 50; | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void setup() { | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int thisPin = pincount - 1; thisPin >= 0; thisPin--) { | ||
pinMode(btnPin[thisPin], INPUT); | ||
digitalWrite(btnPin[thisPin], HIGH); | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Keyboard.begin(); | ||
} | ||
|
||
// Place the actions needed after pin press here | ||
int outputAction(int currentButton) { | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (currentButton == 1) { | ||
Keyboard.press(ctrlKey); | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Keyboard.press('c'); | ||
delay(100); | ||
Keyboard.releaseAll(); | ||
} | ||
if (currentButton + 1 == 2) { | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Keyboard.press(ctrlKey); | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Keyboard.press('v'); | ||
delay(100); | ||
Keyboard.releaseAll(); | ||
} | ||
} | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void loop() { | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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]; | ||
} | ||
} | ||
TheShubham99 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.