upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the ElecFreaks* Joystick v 1.2-1.4 Breakout. More...

Detailed Description

This module defines the Joystick API, and implementation for the X and Y buttons could be treated as normal GPIO - this enables easier interrupt support. This driver should be compatible with any 2-axis analog joystick.

joystick12.jpg
int
main(int argc, char** argv)
{
// Instantiate a joystick on analog pins A0 and A1
upm::Joystick12 sensor(0, 1);
signal(SIGINT, sig_handler);
// Print the X and Y input values every second
while (!is_running) {
float x = sensor.getXInput();
float y = sensor.getYInput();
std::cout << "Driving X:" << x << ": and Y:" << y << std::endl;
upm_delay(1);
}
std::cout << "exiting application" << std::endl;
return 0;
}

Public Member Functions

 Joystick12 (int pinX, int pinY)
 
 ~Joystick12 ()
 
float getXInput ()
 
float getYInput ()
 

Constructor & Destructor Documentation

Joystick12 ( int  pinX,
int  pinY 
)

Instantiates a Joystick object

Parameters
pinXAnalog pin where the X input is connected
pinYAnalog pin where the Y input is connected
~Joystick12 ( )

Joystick object destructor

Member Function Documentation

float getXInput ( )

Gets the X input

Returns
float X value, ranging from -1 to 1; 0 is mid
float getYInput ( )

Gets the Y input

Returns
float Y value, ranging from -1 to 1; 0 is mid

The documentation for this class was generated from the following files: