MPU6050 with I2C. NO LCD

Dependencies:   mbed

Revision:
4:0bbb594dd933
Parent:
3:02533f8628e4
--- a/main.cpp	Sun Apr 19 13:04:46 2020 +0000
+++ b/main.cpp	Tue May 05 13:09:37 2020 +0000
@@ -28,6 +28,7 @@
  
 #include "mbed.h"
 #include "MPU6050.h"
+#include "stdio.h"
 //#include "N5110.h"
 
 // Using NOKIA 5110 monochrome 84 x 48 pixel display
@@ -38,6 +39,30 @@
 // pin 6 - LCD reset (RST)
 //Adafruit_PCD8544 display = Adafruit_PCD8544(9, 8, 7, 5, 6);
 
+
+//as been converted to not use LCD and to print to putty
+
+int sleepDuration = 5; 
+
+void mpuLoop(void);
+
+volatile float yawLow; 
+volatile float yawHigh;   
+ 
+volatile float pitchLow; 
+volatile float pitchHigh; 
+
+volatile float rollLow; 
+volatile float rollHigh; 
+
+void buttonISR(const char*);
+
+InterruptIn Zero_system(PD_0);
+InterruptIn Off_standby(PD_1);
+
+static const char* zero_system_notification = "systemZero";
+static const char* off_standby_notification = "systemStandby"; 
+
 float sum = 0;
 uint32_t sumCount = 0;
 
@@ -56,9 +81,16 @@
   //Set up I2C
   i2c.frequency(400000);  // use fast (400 kHz) I2C   
   
+  
+     // Put in main 
+    Zero_system.rise(&buttonISR,zero_system_notification);  // attach the address of the flip function to the rising edge  
+    Off_standby.rise(&buttonISR,off_standby_notification);  // attach the address of the flip function to the rising edge    
+
+  
+  
   t.start();        
   
-
+ 
   
     
   // Read the WHO_AM_I register, this is a good test of communication
@@ -108,8 +140,27 @@
 
 
 
+buttonISR(zero_system_notification);
+
+
+
  while(1) {
   
+  
+  
+  mpuLoop();
+
+  
+    
+    
+}
+
+
+
+}
+
+
+void mpuLoop(void){
   // If data ready bit set, all data registers have new data
   if(mpu6050.readByte(MPU6050_ADDRESS, INT_STATUS) & 0x01) {  // check if data ready interrupt
     mpu6050.readAccelData(accelCount);  // Read the x/y/z adc values
@@ -147,9 +198,9 @@
    // Pass gyro rate as rad/s
     mpu6050.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f);
 
-    // Serial print and/or display at 0.5 s rate independent of data rates
+//     Serial print and/or display at 0.5 s rate independent of data rates
    // delt_t = t.read_ms() - count;
-   // if (delt_t > 500) { // update LCD once per half-second independent of read rate
+ //   if (delt_t > 500) { // update LCD once per half-second independent of read rate
 
     pc.printf("ax = %f", 1000*ax); 
     pc.printf(" ay = %f", 1000*ay); 
@@ -185,13 +236,13 @@
     yaw   *= 180.0f / PI; 
     roll  *= 180.0f / PI;
 
-//    pc.printf("Yaw, Pitch, Roll: \n\r");
-//    pc.printf("%f", yaw);
-//    pc.printf(", ");
-//    pc.printf("%f", pitch);
-//    pc.printf(", ");
-//    pc.printf("%f\n\r", roll);
-//    pc.printf("average rate = "); pc.printf("%f", (sumCount/sum)); pc.printf(" Hz\n\r");
+    pc.printf("Yaw, Pitch, Roll: \n\r");
+  pc.printf("%f", yaw);
+  pc.printf(", ");
+    pc.printf("%f", pitch);
+    pc.printf(", ");
+   pc.printf("%f\n\r", roll);
+   pc.printf("average rate = "); pc.printf("%f", (sumCount/sum)); pc.printf(" Hz\n\r");
 
      pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll);
      pc.printf("average rate = %f\n\r", (float) sumCount/sum);
@@ -202,7 +253,54 @@
     sumCount = 0; 
     
     //wait(0.5); //So i can read the data 
-}
+    
+
+    
+    if(yaw > yawHigh || yaw < yawLow || pitch > pitchHigh || pitch < pitchLow || roll > rollHigh || roll < rollLow ){
+        
+      printf("\n\nTHEFT ATTEMPT\n\n"); 
+        
+        }
+    }
+      
+
+ 
+ 
+
+
+
+
+void buttonISR(const char* parameter) {
+printf("\n\r%s",parameter); 
+   if(parameter == zero_system_notification){
+       printf("\n\n\nZERO\n\n\n");
+       
+yawLow = yaw - 30; 
+yawHigh = yaw + 30; 
+
+pitchLow = pitch - 30;
+pitchHigh = pitch + 30;
+
+rollLow = roll - 30;
+rollHigh = roll + 30; 
+
+       
+       //steps
+//will have to create a relica variable of yaw pitch roll and then compare in an iff statement statement. 
+//e.g yaw 2+ and yaw2- ====  yaw2+ = yaw +10. & yaw 2- = yaw-10. if(yaw > yaw2+ || yaw <yaw2-){  trigger alarm    }
+
+
+//if statemenet for yaw,pitch,roll. if statment where is greater or smaller than 10 either way a light is lit.
+//light becomes text message 
+//zero is done with button
+       
+       }
+//static const char* off_standby_notification = "systemStandby"; 
+   if(parameter == off_standby_notification){
+       printf("\n\n\nSTANDBY\n\n\n");
+       }    
 }
- 
+
+
+
  
\ No newline at end of file