-blinking LEDs using push button -motion sensor detection and printing to uart

Dependencies:   LIS3DSH mbed

Files at this revision

API Documentation at this revision

Comitter:
rakeshravula
Date:
Sat Jun 23 02:43:09 2018 +0000
Parent:
0:dc6b1f4adb5a
Commit message:
Updated to show LEDS based on the direction you move the board using in built accelorometer;

Changed in this revision

USBDevice.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
diff -r dc6b1f4adb5a -r 3cded0feb65d USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sat Jun 23 02:43:09 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#53949e6131f6
diff -r dc6b1f4adb5a -r 3cded0feb65d main.cpp
--- a/main.cpp	Sun Jun 17 08:27:19 2018 +0000
+++ b/main.cpp	Sat Jun 23 02:43:09 2018 +0000
@@ -1,12 +1,13 @@
 #include "mbed.h"
 #include "LIS3DSH.h"
+#include "USBSerial.h"
 
 DigitalOut myledG(PD_12);
 DigitalOut myledO(PD_13);
 DigitalOut myledR(PD_14);
 DigitalOut myledB(PD_15);
 InterruptIn button(PA_0);
-Serial uart(PC_6,PC_7);
+USBSerial uart;//(PC_6,PC_7);
  LIS3DSH acc(PA_7, PA_6, PA_5, PE_3);
  
 char buttondetect = 0;
@@ -15,7 +16,7 @@
     buttondetect = 1;
     }
 int main() {
-   uart.baud(9600);
+   //uart.baud(9600);
   
    button.fall(&buttonIsr); 
    
@@ -33,6 +34,44 @@
         acc.ReadAngles(&roll, &pitch);      //read roll and pitch angles
         uart.printf("X: %d  Y: %d  Z: %d\n", X, Y, Z);
         uart.printf("Roll: %f   Pitch: %f\n", roll, pitch);
+        if(X > 0 && Y >0)
+                    {
+                        myledO = !myledO;
+                        myledB = 0;
+                        myledR = 0;
+                        myledG = 0;
+                        uart.printf("Yes...entered to Orange Roll: %f   Pitch: %f\n", roll, pitch);
+                        
+                        }
+    
+            else if(X < 0 && Y < 0)
+            {
+                myledB = !myledB;
+                myledG = 0;
+                        myledR = 0;
+                        myledO = 0;
+                 uart.printf("Yes..entered to blue Roll: %f   Pitch: %f\n", roll, pitch);
+                }
+                else if(X < 0 && Y > 0)
+                {
+                    myledG = !myledG;
+                    myledO = 0;
+                        myledR = 0;
+                        myledB = 0;
+                    uart.printf("Yes..entered to Green Roll: %f   Pitch: %f\n", roll, pitch);
+                    
+                    }
+                else if(X >0 && Y < 0)
+                {
+                    myledR = !myledR;
+                    myledB = 0;
+                        myledO = 0;
+                        myledG = 0;
+                    uart.printf("Yes...entered to Red Roll: %f   Pitch: %f\n", roll, pitch);
+                    }
+                    
+                
+        
    
         if(buttondetect){
             buttondetect = 0;