Class to drive a joystick module.
Public declarations:
class JoyStick{ public: JoyStick(); void begin(byte xAxisPin, byte yAxisPin, byte zButtonPin); void axisConfig(int normalizeTo, byte tolerance, boolean zIgnoreXY=false); void run(); int readXAxis(); int readYAxis(); boolean readZButton(); protected: virtual void onZButtonPressed(){} virtual void onZButtonReleased(){} virtual void onXAxisChange(int xVal){} virtual void onYAxisChange(int yVal){} };
Call begin() before any other method informing arduino's pins.
You can configurate the readings by calling axisConfig() method.
Use readXAxis() and readYAxis() to read axis values and readZButton() to read button Z status.
If you prefer to work with events, derive JoyStick class and rewrite them. In this case, dont forget to call run() method at least once per loop.
Call before any other method. Read axes values to use as reference. This references are considered the origin of axis (zero). Lower readings return negative values.
xAxisPin: x axis pin (analog).
yAxisPin: y axis pin (analog).
zButtonPin: button z pin (digital).
Configure the axes readings. By default, readings of XY axes return values beetwen -512 and 512 (approximately). The normalizeTo parameter make readings to be mapped to informed value. For example, if it is 100, the readings will return values between -100 and 100.
normalizeTo: value to normalize readings of axes.
tolerance: minimum variation of the axes to trigger events (after normalized).
zIgnoreXY: ignore XY axes events when button Z is pressed.
Reads axes and button status and triggers events if needed. If you use events, this method must be called at least once per loop.
Read and return the x axis value. The returned value can be normalized if axisConfig() method was called.
return: x axis value normalized.
Read and return the y axis value. The returned value can be normalized if axisConfig() method was called.
return: y axis value normalized.
Read Z button status.
return: true if Z button is pressed , false if not.
Event triggered when Z button is pressed.
Events are triggered by run() method, so to work with events you must call run() at least once per loop.
Event triggered when Z button is released.
Events are triggered by run() method, so to work with events you must call run() at least once per loop.
Event triggered when X axis value change at least the tolerance informed in axisConfig() method (default=1).
Events are triggered by run() method, so to work with events you must call run() at least once per loop.
Event triggered when Y axis value change at least the tolerance informed in axisConfig() method (default=1).
Events are triggered by run() method, so to work with events you must call run() at least once per loop.
Wiki: Home
Wiki: JoyStickShield
Wiki: JsRadioMaster
Wiki: JsRadioSlave
Wiki: PushButton