EasyManua.ls Logo

sparkfun Pro Micro - Page 21

sparkfun Pro Micro
27 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
/*HIDJoystickMouseExample
by:JimLindblom
date:1/12/2012
license:MITLicenseFeelfreetousethiscodeforanyp
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
7

Related product manuals