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 -

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //Uses x & y acceleration to simulate a bubble level
00002 //on the application board LCD display
00003 #include "mbed.h"
00004 #include "MMA7660.h"
00005 #include "C12832_lcd.h"
00006 
00007 C12832_LCD lcd; //On board LCD display
00008 MMA7660 MMA(p28, p27); //I2C Accelerometer
00009 DigitalOut connectionLed(LED1);//Accel OK LED
00010 
00011 int main()
00012 {
00013     int x=0,y=0;
00014     lcd.cls(); //clear LCD screen
00015     if (MMA.testConnection())
00016         connectionLed = 1; //Accelerometer init OK
00017     while(1) {
00018         //read X,Y +/-Gs and scale for #display pixels
00019         x = (x + MMA.x() * 32.0)/2.0;
00020         y = (y -(MMA.y() * 16.0))/2.0;
00021         lcd.fillcircle(x+63, y+15, 3, 1); //draw bubble
00022         lcd.circle(63, 15, 8, 1);
00023         wait(.1); //time delay
00024         lcd.fillcircle(x+63, y+15, 3, 0); //erase bubble
00025     }
00026 
00027 }