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 -

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Sun Sep 22 17:44:42 2013 +0000
Parent:
0:bd0546063b0a
Commit message:
ver 1.0 see https://mbed.org/users/4180_1/notebook/mbed-application-board-hands-on-demos/

Changed in this revision

C12832_lcd.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Sun Sep 22 17:44:42 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
--- 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
     }
 
 }