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

Committer:
mbedAustin
Date:
Fri Sep 05 19:47:30 2014 +0000
Revision:
0:6641b7d213c1
Seeed Grove Thumb Joystick Analog module, interrupt based example application that outputs the X, Y and button press's to the terminal.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 0:6641b7d213c1 1 #include "mbed.h"
mbedAustin 0:6641b7d213c1 2
mbedAustin 0:6641b7d213c1 3 AnalogIn xAxis(A0);
mbedAustin 0:6641b7d213c1 4 AnalogIn yAxis(A1);
mbedAustin 0:6641b7d213c1 5
mbedAustin 0:6641b7d213c1 6 int x,y,button; // global variables to hold values
mbedAustin 0:6641b7d213c1 7 Ticker joystick; // recurring interrupt to get joystick data
mbedAustin 0:6641b7d213c1 8
mbedAustin 0:6641b7d213c1 9 void joystick_Int_Handler()
mbedAustin 0:6641b7d213c1 10 {
mbedAustin 0:6641b7d213c1 11 x = xAxis.read() * 1000; // float (0->1) to int (0-1000)
mbedAustin 0:6641b7d213c1 12 y = yAxis.read() * 1000;
mbedAustin 0:6641b7d213c1 13 if ( (x > 900) || (y > 900) )
mbedAustin 0:6641b7d213c1 14 button = 1;
mbedAustin 0:6641b7d213c1 15 else
mbedAustin 0:6641b7d213c1 16 button = 0;
mbedAustin 0:6641b7d213c1 17 }
mbedAustin 0:6641b7d213c1 18
mbedAustin 0:6641b7d213c1 19 int main()
mbedAustin 0:6641b7d213c1 20 {
mbedAustin 0:6641b7d213c1 21 // init interrupt, call every .2s
mbedAustin 0:6641b7d213c1 22 joystick.attach(joystick_Int_Handler,0.2);
mbedAustin 0:6641b7d213c1 23
mbedAustin 0:6641b7d213c1 24 // Print out the variables
mbedAustin 0:6641b7d213c1 25 while(1){
mbedAustin 0:6641b7d213c1 26 printf("\rX=%3d, Y=%3d, Button=%d",x,y,button);
mbedAustin 0:6641b7d213c1 27 }
mbedAustin 0:6641b7d213c1 28 }