-
Notifications
You must be signed in to change notification settings - Fork 32
Added an example code to control Keyboard and Mouse from Arduino #15
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
Arsh0508
wants to merge
8
commits into
arduino-libraries:master
Choose a base branch
from
Arsh0508: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 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10708e4
Create Mouse_Control.h
Arsh0508 8abbb81
Create KeyboardandMouseControl.ino
Arsh0508 044f538
Delete Mouse_Control.h
Arsh0508 a11af37
Updated examples/MouseControl/KeyboardandMouseControl.ino
Arsh0508 499b633
Rename examples/MouseControl/KeyboardandMouseControl.ino to examples/…
Arsh0508 d078f7e
Update KeyboardandMouseControl.ino
Arsh0508 ff3d6e1
Add files via upload
Arsh0508 0ad2a86
Add files via upload
Arsh0508 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,93 @@ | ||
/* | ||
KeyboardAndMouseControl | ||
|
||
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. | ||
|
||
Hardware: | ||
- five pushbuttons attached to D2, D3, D4, D5, D6 | ||
|
||
The mouse movement is always relative. This sketch reads four pushbuttons, and | ||
uses them to set the movement of the mouse. | ||
|
||
WARNING: When you use the Mouse.move() command, the Arduino takes over your | ||
mouse! Make sure you have control before you use the mouse commands. | ||
|
||
created 15 Mar 2012 | ||
modified 27 Mar 2012 | ||
by Tom Igoe | ||
|
||
This example code is in the public domain. | ||
|
||
http://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl | ||
*/ | ||
|
||
#include "Keyboard.h" | ||
#include "Mouse.h" | ||
|
||
// set pin numbers for the five buttons: | ||
const int upButton = 2; | ||
const int downButton = 3; | ||
const int leftButton = 4; | ||
const int rightButton = 5; | ||
const int mouseButton = 6; | ||
|
||
void setup() { // initialize the buttons' inputs: | ||
pinMode(upButton, INPUT); | ||
pinMode(downButton, INPUT); | ||
pinMode(leftButton, INPUT); | ||
pinMode(rightButton, INPUT); | ||
pinMode(mouseButton, INPUT); | ||
|
||
Serial.begin(9600); | ||
// initialize mouse control: | ||
Mouse.begin(); | ||
Keyboard.begin(); | ||
} | ||
|
||
void loop() { | ||
// use serial input to control the mouse: | ||
if (Serial.available() > 0) { | ||
char inChar = Serial.read(); | ||
|
||
switch (inChar) { | ||
case 'u': | ||
// move mouse up | ||
Mouse.move(0, -40); | ||
break; | ||
case 'd': | ||
// move mouse down | ||
Mouse.move(0, 40); | ||
break; | ||
case 'l': | ||
// move mouse left | ||
Mouse.move(-40, 0); | ||
break; | ||
case 'r': | ||
// move mouse right | ||
Mouse.move(40, 0); | ||
break; | ||
case 'm': | ||
// perform mouse left click | ||
Mouse.click(MOUSE_LEFT); | ||
break; | ||
} | ||
} | ||
|
||
// use the pushbuttons to control the keyboard: | ||
if (digitalRead(upButton) == HIGH) { | ||
Keyboard.write('u'); | ||
} | ||
if (digitalRead(downButton) == HIGH) { | ||
Keyboard.write('d'); | ||
} | ||
if (digitalRead(leftButton) == HIGH) { | ||
Keyboard.write('l'); | ||
} | ||
if (digitalRead(rightButton) == HIGH) { | ||
Keyboard.write('r'); | ||
} | ||
if (digitalRead(mouseButton) == HIGH) { | ||
Keyboard.write('m'); | ||
} | ||
|
||
} |
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.