Dependencies:   MMA8451Q TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
pemb4660
Date:
Wed Jun 08 16:04:32 2016 +0000
Commit message:
hyi8ndsfop;

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
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 c5a6d47904dc MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Wed Jun 08 16:04:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r c5a6d47904dc TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Wed Jun 08 16:04:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 000000000000 -r c5a6d47904dc main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 08 16:04:32 2016 +0000
@@ -0,0 +1,112 @@
+#include "mbed.h"
+#include "TSISensor.h"
+#include "MMA8451Q.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main()
+{
+    PwmOut gled(LED_GREEN);
+    TSISensor tsi;
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    DigitalOut lefthigh(PTC11);
+    DigitalOut leftlow(PTC9);
+    DigitalOut righthigh(PTC6);
+    DigitalOut rightlow(PTA5);
+    DigitalOut forwardhigh(PTC16);
+    DigitalOut forwardlow(PTD0);
+    DigitalOut backwardhigh(PTA17);
+    DigitalOut backwardlow(PTD1);
+
+
+    bool right;
+    bool forward;
+
+
+    while (1) {
+
+        wait(0.2);
+        float accX=acc.getAccX();
+        printf("x=%0.3f\r\n",accX);
+        if (tsi.readPercentage() != 0) {
+            gled = 1.0 - tsi.readPercentage();
+        }
+
+        if((accX <= 0.1f) && (accX >= -0.1f)) {
+            printf("A \r\n");
+            if (right == true) {
+                printf("B \r\n");
+                righthigh = 0;
+                rightlow = 1;
+            } else {
+                printf("C \r\n");
+                lefthigh = 0;
+                leftlow = 1;
+            }
+            //}
+
+            if (accX > 0.1) {
+                printf("D \r\n");
+                lefthigh = 1;
+                leftlow = 1;
+                righthigh = 0;
+                rightlow = 1;
+                forwardhigh = 1;
+                forwardlow = 1;
+                backwardhigh = 1;
+                backwardlow = 1;
+                right = true;
+            }
+
+            if (accX < -0.1) {
+                printf("E \r\n");
+                lefthigh = 0;
+                leftlow = 1;
+                righthigh = 1;
+                rightlow = 1;
+                forwardhigh = 1;
+                forwardlow = 1;
+                backwardhigh = 1;
+                backwardlow = 1;
+                right = false;
+            }
+            wait(0.1);
+        }
+
+
+        if((acc.getAccY() <= 0.1) && (acc.getAccY() >= -0.1)) {
+            if (forward == true) {
+                forwardhigh = 0;
+                forwardlow = 1;
+            } else
+                backwardhigh = 0;
+            backwardlow = 1;
+        }
+
+        if (acc.getAccY() > 0.1) {
+            lefthigh = 1;
+            leftlow = 1;
+            righthigh = 1;
+            rightlow = 1;
+            forwardhigh = 0;
+            forwardlow = 1;
+            backwardhigh = 1;
+            backwardlow = 1;
+            forward = true;
+        }
+
+        if (acc.getAccY() < -0.1) {
+            lefthigh = 1;
+            leftlow = 1;
+            righthigh = 1;
+            rightlow = 1;
+            forwardhigh = 1;
+            forwardlow = 1;
+            backwardhigh = 0;
+            backwardlow = 1;
+            forward = false;
+        }
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r c5a6d47904dc mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 08 16:04:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file