i purchased arduino compatible joystick, i'm not sure how wire it. presume needs analog input , ground there 5 pins in total. can suggest need plug each of pins? bought from:
http://www.amazon.co.uk/gp/product/b00db76xim?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00
the pins labelled: gnd, +5u, vrx, vry, sw.
any appreciated.
http://www.amazon.co.uk/gp/product/b00db76xim?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00
the pins labelled: gnd, +5u, vrx, vry, sw.
any appreciated.
from sellers website:
code:
#define joys_vrx_dio a0 /* selects input pin joysticks x-axis */
#define joys_vry_dio a1 /* selects input pin joysticks y-axis */
#define joys_sw_dio 2 /* selects input pin joysticks push button */
/* initialises serial , dio */
void setup()
{
/* sets serial port displaying status of sensor */
serial.begin(9600);
/* configures dio pin joysticks push button connected
to. has no pull-up need enable 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 current position of joysticks x & y axis via analogue pins */
serial.print("x axis: ");
serial.print(analogread(joys_vrx_dio));
serial.print(" y axis: ");
serial.print(analogread(joys_vry_dio));
/* reads state of push button , if pressed, outputs state
serial port */
if (!digitalread(joys_sw_dio))
{
serial.println(" button pressed !");
}else
{
serial.println();
}
}
code:
#define joys_vrx_dio a0 /* selects input pin joysticks x-axis */
#define joys_vry_dio a1 /* selects input pin joysticks y-axis */
#define joys_sw_dio 2 /* selects input pin joysticks push button */
/* initialises serial , dio */
void setup()
{
/* sets serial port displaying status of sensor */
serial.begin(9600);
/* configures dio pin joysticks push button connected
to. has no pull-up need enable 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 current position of joysticks x & y axis via analogue pins */
serial.print("x axis: ");
serial.print(analogread(joys_vrx_dio));
serial.print(" y axis: ");
serial.print(analogread(joys_vry_dio));
/* reads state of push button , if pressed, outputs state
serial port */
if (!digitalread(joys_sw_dio))
{
serial.println(" button pressed !");
}else
{
serial.println();
}
}
Arduino Forum > General Category > General Discussion (Moderators: mbanzi, DojoDave, mellis) > arduino joystick wiring
arduino
Comments
Post a Comment