This demo uses the application board’s three axis accelerometer and the LCD display working in graphics mode to build an electronic version of a bubble level.

Dependencies:   C12832_lcd MMA7660 mbed

Fork of MMA7660_HelloWorld by Erik -

Revision:
1:876f52a697c1
Parent:
0:bd0546063b0a
--- a/main.cpp	Wed Oct 17 16:40:45 2012 +0000
+++ b/main.cpp	Sun Sep 22 17:44:42 2013 +0000
@@ -1,21 +1,27 @@
-//Uses the measured z-acceleration to drive leds 2 and 3 of the mbed
-
+//Uses x & y acceleration to simulate a bubble level
+//on the application board LCD display
 #include "mbed.h"
 #include "MMA7660.h"
-
-MMA7660 MMA(p28, p27);
+#include "C12832_lcd.h"
 
-DigitalOut connectionLed(LED1);
-PwmOut Zaxis_p(LED2);
-PwmOut Zaxis_n(LED3);
+C12832_LCD lcd; //On board LCD display
+MMA7660 MMA(p28, p27); //I2C Accelerometer
+DigitalOut connectionLed(LED1);//Accel OK LED
 
-int main() {  
+int main()
+{
+    int x=0,y=0;
+    lcd.cls(); //clear LCD screen
     if (MMA.testConnection())
-        connectionLed = 1;
-        
+        connectionLed = 1; //Accelerometer init OK
     while(1) {
-        Zaxis_p = MMA.z();
-        Zaxis_n = -MMA.z();
+        //read X,Y +/-Gs and scale for #display pixels
+        x = (x + MMA.x() * 32.0)/2.0;
+        y = (y -(MMA.y() * 16.0))/2.0;
+        lcd.fillcircle(x+63, y+15, 3, 1); //draw bubble
+        lcd.circle(63, 15, 8, 1);
+        wait(.1); //time delay
+        lcd.fillcircle(x+63, y+15, 3, 0); //erase bubble
     }
 
 }