actual thing accelerator

Dependencies:   4DGL-uLCD-SE ulcd_accel mbed

Dependents:   ulcd_accel

Files at this revision

API Documentation at this revision

Comitter:
wye11
Date:
Sat Jan 30 07:12:15 2016 +0000
Commit message:
huh

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
MMA8452Q.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 fd0d8678abae 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sat Jan 30 07:12:15 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sparkfun/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r fd0d8678abae MMA8452Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8452Q.lib	Sat Jan 30 07:12:15 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wye11/code/ulcd_accel/#ffbc5d045774
diff -r 000000000000 -r fd0d8678abae main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 30 07:12:15 2016 +0000
@@ -0,0 +1,57 @@
+// Demo for the uLCD-144-G2 and MMA8452Q 3-axis accelerometer
+
+#include "mbed.h"
+#include "MMA8452Q.h"
+#include "uLCD_4DGL.h"
+
+// Graphic LCD - TX, RX, and RES pins
+uLCD_4DGL uLCD(p9,p10,p11);
+
+// Accelerometer - SDA, SCL, and I2C address
+MMA8452Q accel(p28, p27, 0x1D);
+
+int main() {
+
+    // Initialize uLCD
+    uLCD.baudrate(115200);
+    uLCD.background_color(BLACK);
+    uLCD.cls();
+
+    // Initialize accelerometer
+    accel.init();
+
+    // Initial parameters for the circle
+    float x = 64;
+    float y = 64;
+    int radius = 4;
+    int speed = 4;
+
+    // Make a ball "fall" in direction of accelerometer
+    while (1) {
+
+        // Draw a red circle
+        uLCD.filled_circle((int)x, (int)y, radius, RED);
+
+        // Wait before erasing old circle
+        wait(0.02);         // In seconds
+
+        // Erase old circle
+        uLCD.filled_circle((int)x, (int)y, radius, BLACK);
+
+        // Move circle. IMPORTANT! Notice how we adjust for sensor orientation!
+        x -= (speed * accel.readY());
+        y -= (speed * accel.readX());
+
+        // Make circle sit on edges
+        if ( x <= radius + 1 ) {
+            x = radius + 1;
+        } else if ( x >= 126 - radius ) {
+            x = 126 - radius;
+        }
+        if ( y <= radius + 1 ) {
+            y = radius + 1;
+        } else if ( y >= 126 - radius ) {
+            y = 126 - radius;
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r fd0d8678abae mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 30 07:12:15 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file