get direction input from joystick as enum (left, right, up, down, and none)

Dependents:   snake

Files at this revision

API Documentation at this revision

Comitter:
lucoby
Date:
Thu Oct 11 18:54:32 2012 +0000
Commit message:
initial

Changed in this revision

direction.cpp Show annotated file Show diff for this revision Revisions of this file
direction.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d8f0c4ba09cc direction.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/direction.cpp	Thu Oct 11 18:54:32 2012 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+#include "direction.h"
+
+AnalogIn horz(p18);
+AnalogIn vert(p19);
+
+SDirection getDirection(SDirection direction) {
+    float x = horz;
+    float y = vert;
+    if(vert > 0.75) {
+        direction = up;
+    } else if(vert < 0.25) {
+        direction = down;
+    } else if(horz > 0.75) {
+        direction = left;
+    } else if(horz < 0.25) {
+        direction = right;
+    }
+    return direction;
+}
\ No newline at end of file
diff -r 000000000000 -r d8f0c4ba09cc direction.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/direction.h	Thu Oct 11 18:54:32 2012 +0000
@@ -0,0 +1,14 @@
+#ifndef DIRECTION_H
+#define DIRECTION_H
+
+typedef enum {
+    none,
+    left,
+    right,
+    up,
+    down
+} SDirection;
+
+SDirection getDirection(SDirection direction);
+
+#endif