Analogue Joystick Controller (HCARDU0019)

Modules for various types of sensors including accelerometers. gyro's, IR motion, etc
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Analogue Joystick Controller (HCARDU0019)

Post by admin » Wed Mar 02, 2016 11:20 am

Image


Image

PS2 style 2 axis directional joystick, which is compatible with the Arduino interface. Product code for this item is HCARDU0019 and it can be purchased here.


Image

1..............GND
2..............+5V
3..............X-Axis (analogue)
4..............Y-Axis (analogue)
5..............Push button (Connects to GND)


Image

Code: Select all

#define JOYS_VRX_DIO A0    /* Selects the input pin for the joysticks X-Axis */
#define JOYS_VRY_DIO A1    /* Selects the input pin for the joysticks Y-Axis */

#define JOYS_SW_DIO 2      /* Selects the input pin for the joysticks push button */


/* Initialises serial and DIO */
void setup()
{
  /* Sets up the serial port for displaying the status of the sensor */
  Serial.begin(9600);
  
  /* Configures the DIO pin that the joysticks push button will be connected 
     to. As it has no pull-up we will need to enable the Arduino's internal pull-up */
  pinMode(JOYS_SW_DIO, INPUT); 
  digitalWrite(JOYS_SW_DIO, HIGH); // turns on pull-up resistors
}


/* Main program loop */
void loop()
{
  /* Reads the current position of the joysticks X & Y axis via the analogue pins */
  Serial.print("X axis: ");
  Serial.print(analogRead(JOYS_VRX_DIO));
  Serial.print("  Y axis: ");
  Serial.print(analogRead(JOYS_VRY_DIO));
  
  /* Reads the state of the push button and if pressed, outputs the state to the 
     serial port */
  if (!digitalRead(JOYS_SW_DIO))
  {
    Serial.println("  Button pressed !");
  }else
  {
     Serial.println();
  }
}

Post Reply

Return to “Sensors”