when the user shakes the board, then on board led toggles to a different color

Dependencies:   MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
aji052
Date:
Sat Oct 10 09:26:09 2015 +0000
Commit message:
when the user shakes the board, the on board led toggles to different colours

Changed in this revision

MMA8451Q.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b3a1604a669c MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Sat Oct 10 09:26:09 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r b3a1604a669c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Oct 10 09:26:09 2015 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+Serial pc(USBTX,USBRX);
+DigitalOut red(LED1);
+DigitalOut green(LED2);
+DigitalOut blue(LED3);
+int i=0;
+int xaxis, yaxis, zaxis;
+int main(void)
+{
+    while(1)
+    {
+        xaxis=(acc.getAccX()+1)*100;
+        yaxis=(acc.getAccY()+1)*100;
+        zaxis=(acc.getAccZ()+1)*100;
+        pc.printf("$%d %d %d;",xaxis,yaxis,zaxis);
+        
+        if ( xaxis>=250 || yaxis >= 250 || zaxis >= 250)
+        i++;
+        
+        if(i==1)
+        {red=0;
+         green=1;
+         blue=1;
+         }
+         if(i==2)
+        {red=1;
+         green=0;
+         blue=1;
+         }
+         if(i==3)
+        {red=1;
+         green=1;
+         blue=0;
+         i=0;
+         }
+        wait(0.1);
+        }
+        }
+        
+        
\ No newline at end of file
diff -r 000000000000 -r b3a1604a669c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Oct 10 09:26:09 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file