Seeed / Mbed 2 deprecated Seeed_Grove_Thumb_Joystick_Example

Dependencies:   mbed

Fork of Seeed_Grove_Thumb_Joystick_Example by Austin Blackstone

Files at this revision

API Documentation at this revision

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

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6641b7d213c1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 05 19:47:30 2014 +0000
@@ -0,0 +1,28 @@
+#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);
+    }
+}
diff -r 000000000000 -r 6641b7d213c1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 05 19:47:30 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file