Freedom Seeed Grove Joystick Example

Dependencies:   mbed

Fork of frdm_Grove_Joystick_Example by Freescale

Simply Import this Program into your mbed compiler
Select Compile to generate the binary file
Open an Hyperterminal window and connect to the mbed Serial Port (COMxx) peripheral using speed 9600bps
Plug the Grove Shield v2 on the top of your FRDM-K64F
Connect on end of the 4-pin Grove cable to the Temperature and Humidity module and the other end to the port A0 of the Grove Adapter.

/media/uploads/GregC/joystick1.jpg

Drag n drop the frdm_Grove_Joystick_Example_K64F.bin into the mbed drive from your file explorer
Wait for download to complete
Press the Reset/SW1 button of your FRDM-K64F board to launch the program

Your hyperterminal window should now display a value for the X, the Y and the button position of the Joystick (see picture below)!!
X=365 when pushed left, X=727 when centered and X=1000 when pushed right Y=365 when pushed down, X=727 when centered and X=1000 when pushed up Button=1 when pressed and Button=0 when released

/media/uploads/GregC/joystick2.jpg

Committer:
GregC
Date:
Fri Jan 01 16:56:40 2016 +0000
Revision:
0:2f9598399d00
Freedom Seeed Grove Joystick Example

Who changed what in which revision?

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