Created
June 12, 2014 17:34
-
-
Save Strikeskids/21f24da58ba1d4e9392f to your computer and use it in GitHub Desktop.
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
/* | |
KeyboardAndMouseControl | |
Controls the mouse from five pushbuttons on an Arduino Leonardo or Micro. | |
Hardware: | |
* 5 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 code is in the public domain | |
*/ | |
boolean runState=false; | |
boolean tempRunning=false; | |
// set pin numbers for the five buttons: | |
void setup() { // initialize the buttons' inputs: | |
pinMode(4, INPUT); | |
pinMode(3, INPUT); | |
pinMode(2, INPUT); | |
digitalWrite(2,HIGH); | |
digitalWrite(3,HIGH); | |
digitalWrite(4,HIGH); | |
Serial.begin(9600); | |
// initialize mouse control: | |
Mouse.begin(); | |
Keyboard.begin(); | |
} | |
void loop() { | |
// use serial input to control the mouse: | |
if(digitalRead(4)==0) | |
{ | |
if(runState==tempRunning) | |
{ | |
; | |
} | |
else | |
{ | |
if(runState==0) | |
{ | |
runState=!runState; | |
} | |
} | |
} | |
Serial.println(digitalRead(2)); | |
Serial.println(analogRead(A0)); | |
if(runState==0) | |
{ | |
if(digitalRead(3)==0) | |
{ | |
Mouse.click(); | |
} | |
if (digitalRead(2) == 0) | |
{ | |
String temp= "password"; | |
for(int x=0; x<temp.length(); x++) | |
{ | |
Keyboard.write(temp.charAt(x)); | |
} | |
} | |
if(analogRead(A1)<450) | |
{ | |
Mouse.move(0, 10); | |
} | |
else if(analogRead(A1)>600) | |
{ | |
Mouse.move(0, -10); | |
} | |
if(analogRead(A0)<450) | |
{ | |
Mouse.move(10, 0); | |
} | |
else if(analogRead(A0)>600) | |
{ | |
Mouse.move(-10, 0); | |
} | |
} | |
tempRunning=runState; | |
runState=(digitalRead(4)==0); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment