Menu

JoyStickShield

Perrotti

Class JoyStickShield

Driver to Joystick Shield V1.a board.
Generate events from buttons and joystick moves.

Public declarations:

// Button's pins
#define BT_A_PIN 2
#define BT_B_PIN 3
#define BT_C_PIN 4
#define BT_D_PIN 5
#define BT_E_PIN 6
#define BT_F_PIN 7
#define BT_Z_PIN 8

// Button's IDs
#define BT_A_ID 0
#define BT_B_ID 1  
#define BT_C_ID 2
#define BT_D_ID 3
#define BT_E_ID 4
#define BT_F_ID 5
#define BT_Z_ID 6

#define JS_BUTTONS 7

// JoyStick pins
#define X_AXIS_PIN A0
#define Y_AXIS_PIN A1

class JoyStickShield{
public:  
  JoyStickShield();

  void begin();
  void axisConfig(int normalizeTo, byte tolerance, boolean zIgnoreXY=false);
  void run();
  boolean isPressed(byte btId);

protected:
  virtual void onButtonPressed(byte btID){} // Buttons
  virtual void onButtonReleased(byte btID){}
  virtual void onXAxisChange(int xVal){}    // Joystick axis
  virtual void onYAxisChange(int yVal){}
};
How to use

Call begin() before any other method.
Configure axes readings and events by calling axisConfig().
Call run() at least once per loop.
Call isPressed() to check if any button is pressed.

Derive JoyStickShield class and rewrite the events to capture then.


Related

Wiki: Home
Wiki: JoyStick
Wiki: JsRadioMaster
Wiki: JsRadioSlave
Wiki: PushButton
Wiki: PushButtonArray

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.