Grove - Thumb Joystick analog module example application. X, Y button press outputs provided. The joystick also has a push button that is could be used for special applications. When the module is in working mode it will output two analog values representing two directions. The value is restricted in a little smaller range (e.g 200~700)compared to the normal joystick, while it is around 1023 when the button is pushed, so that the MCU can detect the action of pressing.

Dependencies:   mbed

Fork of Seeed_Grove_Thumb_Joystick_Example by Austin Blackstone

main.cpp

Committer:
mbedAustin
Date:
2014-09-05
Revision:
0:6641b7d213c1

File content as of revision 0:6641b7d213c1:

#include "mbed.h"

AnalogIn xAxis(A0);
AnalogIn yAxis(A1);

int x,y,button;  // global variables to hold values
Ticker joystick; // recurring interrupt to get joystick data

void joystick_Int_Handler()
{
    x = xAxis.read() * 1000; // float (0->1) to int (0-1000)
    y = yAxis.read() * 1000;
    if ( (x > 900) || (y > 900) )
        button = 1;
    else
        button = 0;
}

int main() 
{
    // init interrupt, call every .2s
    joystick.attach(joystick_Int_Handler,0.2);
    
    // Print out the variables
    while(1){
        printf("\rX=%3d, Y=%3d, Button=%d",x,y,button);
    }
}