Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832 MMA7660 mbed
Fork of app-board-Bubble-Level by
Diff: main.cpp
- Revision:
- 2:257b84d739a2
- Parent:
- 1:876f52a697c1
--- a/main.cpp Sun Sep 22 17:44:42 2013 +0000
+++ b/main.cpp Thu Feb 19 10:35:58 2015 +0000
@@ -2,26 +2,77 @@
//on the application board LCD display
#include "mbed.h"
#include "MMA7660.h"
-#include "C12832_lcd.h"
+#include "C12832.h"
+
+C12832 lcd(p5, p7, p6, p8, p11); //On board LCD display
+MMA7660 MMA(p28, p27); //I2C Accelerometer
+//Serial pc(USBTX, USBRX);
+//DigitalOut connectionLed(LED1);//Accel OK LED
+BusOut myleds(LED1, LED2, LED3, LED4);
+
+int pow(int x) {
+ int pow = 1;
+ if(x == 0) {
+ return pow;
+ }
+ for(int i = 0; i < x; i++) {
+ pow *= 2;
+ }
+ return pow;
+}
-C12832_LCD lcd; //On board LCD display
-MMA7660 MMA(p28, p27); //I2C Accelerometer
-DigitalOut connectionLed(LED1);//Accel OK LED
-
+void motion_detect() {
+ if(MMA.y() < -0.5) {
+ lcd.cls();
+ lcd.locate(55,12);
+ lcd.printf("UP");
+ for(int i = 0; i < 4; i++) {
+ myleds = pow(i);
+ wait(0.05);
+ }
+ myleds = 0;
+ }
+
+ if(MMA.y() > 0.5) {
+ lcd.cls();
+ lcd.locate(55,12);
+ lcd.printf("DOWN");
+ for(int i = 3; i >= 0; i--) {
+ myleds = pow(i);
+ wait(0.05);
+ }
+ myleds = 0;
+ }
+
+ if(MMA.x() < -0.5) {
+ lcd.cls();
+ lcd.locate(55,12);
+ lcd.printf("RIGHT");
+ myleds = 6;
+ wait(0.05);
+ myleds = 9;
+ wait(0.05);
+ myleds = 0;
+ }
+
+ if(MMA.x() > 0.5) {
+ lcd.cls();
+ lcd.locate(55,12);
+ lcd.printf("LEFT");
+ myleds = 9;
+ wait(0.05);
+ myleds = 6;
+ wait(0.05);
+ myleds = 0;
+ }
+}
+
int main()
{
- int x=0,y=0;
lcd.cls(); //clear LCD screen
if (MMA.testConnection())
- connectionLed = 1; //Accelerometer init OK
+ myleds = 15; //Accelerometer init OK
while(1) {
- //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
+ motion_detect();
}
-
}
