Reply to topic  [ 1 post ] 
Analogue Joystick Controller (HCARDU0019) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 650
Post Analogue Joystick Controller (HCARDU0019)
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:
#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();
  }
}


Wed Mar 02, 2016 11:20 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD