![](/media/cache/profiles/ibmfp2.jpg.50x50_q85.jpg)
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
main.cpp@1:876f52a697c1, 2013-09-22 (annotated)
- Committer:
- 4180_1
- Date:
- Sun Sep 22 17:44:42 2013 +0000
- Revision:
- 1:876f52a697c1
- Parent:
- 0:bd0546063b0a
ver 1.0 see https://mbed.org/users/4180_1/notebook/mbed-application-board-hands-on-demos/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 1:876f52a697c1 | 1 | //Uses x & y acceleration to simulate a bubble level |
4180_1 | 1:876f52a697c1 | 2 | //on the application board LCD display |
Sissors | 0:bd0546063b0a | 3 | #include "mbed.h" |
Sissors | 0:bd0546063b0a | 4 | #include "MMA7660.h" |
4180_1 | 1:876f52a697c1 | 5 | #include "C12832_lcd.h" |
Sissors | 0:bd0546063b0a | 6 | |
4180_1 | 1:876f52a697c1 | 7 | C12832_LCD lcd; //On board LCD display |
4180_1 | 1:876f52a697c1 | 8 | MMA7660 MMA(p28, p27); //I2C Accelerometer |
4180_1 | 1:876f52a697c1 | 9 | DigitalOut connectionLed(LED1);//Accel OK LED |
Sissors | 0:bd0546063b0a | 10 | |
4180_1 | 1:876f52a697c1 | 11 | int main() |
4180_1 | 1:876f52a697c1 | 12 | { |
4180_1 | 1:876f52a697c1 | 13 | int x=0,y=0; |
4180_1 | 1:876f52a697c1 | 14 | lcd.cls(); //clear LCD screen |
Sissors | 0:bd0546063b0a | 15 | if (MMA.testConnection()) |
4180_1 | 1:876f52a697c1 | 16 | connectionLed = 1; //Accelerometer init OK |
Sissors | 0:bd0546063b0a | 17 | while(1) { |
4180_1 | 1:876f52a697c1 | 18 | //read X,Y +/-Gs and scale for #display pixels |
4180_1 | 1:876f52a697c1 | 19 | x = (x + MMA.x() * 32.0)/2.0; |
4180_1 | 1:876f52a697c1 | 20 | y = (y -(MMA.y() * 16.0))/2.0; |
4180_1 | 1:876f52a697c1 | 21 | lcd.fillcircle(x+63, y+15, 3, 1); //draw bubble |
4180_1 | 1:876f52a697c1 | 22 | lcd.circle(63, 15, 8, 1); |
4180_1 | 1:876f52a697c1 | 23 | wait(.1); //time delay |
4180_1 | 1:876f52a697c1 | 24 | lcd.fillcircle(x+63, y+15, 3, 0); //erase bubble |
Sissors | 0:bd0546063b0a | 25 | } |
Sissors | 0:bd0546063b0a | 26 | |
Sissors | 0:bd0546063b0a | 27 | } |