/*HIDJoystickMouseExample
by:JimLindblom
date:1/12/2012
license:MITLicenseFeelfreetousethiscodeforanyp
urpose.
Norestrictions.Justkeepthislicenseifyougoontous
ethis
codeinyourfutureendeavors!Reuseandshare.
Thisisverysimplisticcodethatal
lowsyoutoturnthe
SparkFunThumbJoystick(http://www.sparkfun.com/products/9
032)
intoanHIDMouse.Theselectbutton onthejoystickisse
tup
asthemouseleftclick.
*/
int horzPin= A0;//Analogoutputofhorizontaljoystickpin
int vertPin= A1;//Analogoutputofverticaljoystickpin
int selPin=9;
//selectbuttonpinofjoystick
int vertZero,horzZero;//Storestheinitialvalueofeacha
xis,usuallyaround512
int vertValue,horzValue;//Storescurrentanalogoutputof
eachaxis
const int sensitivity= 200;//Highersensitivityvalue=sl
owermouse,shouldbe<=about500
int mouseClickFlag=0;
void setup()
{
pinMode(horzPin,INPUT);//Setbothanalogpin
sasinputs
pinMode(vertPin,INPUT);
pinMode(selPin,INPUT);//setbuttonselectpinasinput
digitalWrite(selPin,HIGH);//Pullbuttonselectpinhigh
delay(1000);//shortdelaytoletoutputssettle
vertZero= analogRead(vertPin);//gettheinitialvalues
horzZero= analogRead(horzPin);//Joystickshouldbeinne
utralpositionwhe nreadingthese
}
void loop()
{
vertV
alue= analogRead(vertPin) vertZero;//readvertica
loffset
horzValue= analogRead(horzPin) horzZero;//readhorizon
taloffset
Page 21 of 2