Library for Sparkfun analog joystick
Fork of SparkfunAnalogJoystick by
Revision 1:ed0057aa2e31, committed 2015-03-08
- Comitter:
- ryanzhang1994
- Date:
- Sun Mar 08 05:43:45 2015 +0000
- Parent:
- 0:ed9ee35481a9
- Child:
- 2:4761030c1a7d
- Commit message:
- Sparkfun Analog Joystick Library
Changed in this revision
SparkfunAnalogJoystick.cpp | Show annotated file Show diff for this revision Revisions of this file |
SparkfunAnalogJoystick.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SparkfunAnalogJoystick.cpp Sat Mar 07 23:28:06 2015 +0000 +++ b/SparkfunAnalogJoystick.cpp Sun Mar 08 05:43:45 2015 +0000 @@ -3,23 +3,28 @@ #define M_PI 3.14159265358979323846 +// Constructor SparkfunAnalogJoystick::SparkfunAnalogJoystick(PinName vert, PinName horz, PinName sel): VERT(vert), HORZ(horz), SEL(sel) { SEL.mode(PullUp); } +// Get the button status int SparkfunAnalogJoystick::button(){ return 1-SEL; } +// X axis value, reverse the value to get the x value in a normal Cartesian coordinate system float SparkfunAnalogJoystick::xAxis(){ return -(HORZ-0.5)*2; } +// Y axis value float SparkfunAnalogJoystick::yAxis(){ return (VERT-0.5)*2; } +// Calculate the angle value in a polar coordinate system float SparkfunAnalogJoystick::angle(){ float horz=-(HORZ-0.5)*2; float vert=(VERT-0.5)*2; @@ -34,6 +39,7 @@ return angle; } +// Calculate the normalized distance value in a polar coordinate system float SparkfunAnalogJoystick::distance(){ float horz=-(HORZ-0.5)*2; float vert=(VERT-0.5)*2;
--- a/SparkfunAnalogJoystick.h Sat Mar 07 23:28:06 2015 +0000 +++ b/SparkfunAnalogJoystick.h Sun Mar 08 05:43:45 2015 +0000 @@ -5,19 +5,21 @@ class SparkfunAnalogJoystick { -public: - SparkfunAnalogJoystick(PinName, PinName, PinName); - - int button(); - - float xAxis(); +public: + // Constructor + SparkfunAnalogJoystick(PinName, PinName, PinName); + // Get the button status, 1 for on and 0 for off + int button(); + // X axis value + float xAxis(); + // Y axis value float yAxis(); - + // Angle value in polar coordinates float angle(); - + // Distance value in polar coordinates float distance(); - + protected: AnalogIn VERT; AnalogIn HORZ;