Skip to content
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

Created KeyboardandMousecontrol.ino #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions examples/KeyboardandMouseControl/KeyboardandMouseControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
This example has been moved to File > Examples > USB > KeyboardAndMouseControl
https://github.com/arduino/Arduino/tree/master/build/shared/examples/09.USB/KeyboardAndMouseControl
*/

/*
KeyboardAndMouseControl

Comment on lines +1 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
This example has been moved to File > Examples > USB > KeyboardAndMouseControl
https://github.com/arduino/Arduino/tree/master/build/shared/examples/09.USB/KeyboardAndMouseControl
*/
/*
KeyboardAndMouseControl

This makes no sense. The example has not been moved to File > Examples > USB > KeyboardAndMouseControl. The example has always been there. The whole point of your pull request is to move (or copy) that sketch FROM File > Examples > USB > KeyboardAndMouseControl TO File > Examples > Mouse > KeyboardAndMouseControl.

There is no benefit to providing a link to the copy of the sketch in the arduino/Arduino repository. If they saw that comment, the user is already looking at the sketch.

Controls the mouse from five pushbuttons on a native USB board (e.g., Leonardo,
Micro, MKR, Nano 33 IoT, Zero, 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');
}

}
Binary file added examples/KeyboardandMouseControl/layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/KeyboardandMouseControl/schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.