Final Project

Dependencies:   mbed-os FXAS21000 LED_Bar FXOS8700Q

Files at this revision

API Documentation at this revision

Comitter:
maeconn
Date:
Tue Apr 26 23:07:20 2022 +0000
Parent:
2:d08625231a9f
Commit message:
FinalProject

Changed in this revision

LED_Bar.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LED_Bar.lib	Tue Apr 26 23:07:20 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Seeed/code/LED_Bar/#edcb13b58b4f
--- a/main.cpp	Tue Apr 26 21:26:04 2022 +0000
+++ b/main.cpp	Tue Apr 26 23:07:20 2022 +0000
@@ -2,6 +2,7 @@
 #include "FXOS8700Q.h"
 #include "FXAS21000.h"
 #include "hcsr04.h"
+#include "LED_Bar.h"
     I2C i2c(PTE25, PTE24);
     Serial pc(USBTX,USBRX);
     FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);    // Configured for the FRDM-K64F with onboard sensors
@@ -9,40 +10,21 @@
     FXAS21000 gyro(D14,D15);
     HCSR04 usensor1(D8,D9);                     //ECHO Pin=D9, TRIG Pin=D8
     HCSR04 usensor2(D7,D6);                     //ECHO Pin=D7, TRIG Pin=D6
+    LED_Bar bar(D5,D4);
+    DigitalOut buzzer(D2);
+    int buzz_on=1, buzz_off=0;
 
     int main(void)
     {
         int num = 0;
         int distance1, distance2;
+        int led_speed;
         float dist_remaining1, dist_percent1, dist_remaining2, dist_percent2;
         char snd[255],rcv[1000];                    //snd: send command to ESP8266
                                             //rcv: receive response from ESP8266
 
         //Ultrasound Sensor (HC-SR04) #1 Initialization
         int a = 30;
-        usensor1.start();
-        wait_ms(500);
-        
-    //Calculating Distance Percentage Remaining for Sensor # 1
-        distance1 = usensor1.get_dist_cm();
-        dist_remaining1 = a-distance1;
-        dist_percent1 = (dist_remaining1/30)*100;
-        
-    //LED and Tera Term Output
-        if (distance1<30 && distance2<30) {
-            //RLed = 1;
-//            BLed = 1;
-//            GLed = 0;
-            pc.printf("You are colse!\n\r"); while(1) {
-                    pc.putc(pc.getc() + 1);}
-            //printf("Percent remaining: %f\r", dist_percent1 && dist_percent2);
-        } else {
-            //GLed = 1;
-//            BLed = 1;
-//            RLed = 0;
-            pc.printf("You are far!\n\r"); while(1) {
-                    pc.putc(pc.getc() + 1);}
-            }
         float gyro_data[3];
         motion_data_units_t acc_data, mag_data;
         motion_data_counts_t acc_raw, mag_raw;
@@ -50,12 +32,12 @@
         int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int;
         acc.enable();
         mag.enable();
-        DigitalOut Red(LED1);
-        Red=1;
-        DigitalOut Blue(LED3);
-        DigitalOut Green(LED2);
-        Blue=1;
-        Green=1;
+        //DigitalOut Red(LED1);
+//        Red=1;
+//        DigitalOut Blue(LED3);
+//        DigitalOut Green(LED2);
+//        Blue=1;
+//        Green=1;
         
         while (true) {
             // counts based results
@@ -81,15 +63,48 @@
            gyro.ReadXYZ(gyro_data);
            pc.printf("FXAS21000  Gyro: X=%6.2f   Y=%6.2f    Z=%6.2f\r\n", gyro_data[0],gyro_data[1], gyro_data[2]);
            
+           
+           usensor1.start();
+            wait_ms(500);
+        
+    //Calculating Distance Percentage Remaining for Sensor # 1
+            distance1 = usensor1.get_dist_cm();
+            dist_remaining1 = a-distance1;
+            dist_percent1 = (dist_remaining1/30)*100;
+        
+    ////LED and Tera Term Output
+//            if (distance1<30 && distance2<30) {
+//            
+//            pc.printf("You are colse!\n\r"); while(1) {
+//                    pc.putc(pc.getc() + 1);}
+//            //printf("Percent remaining: %f\r", dist_percent1 && dist_percent2);
+//        } else {
+//            //GLed = 1;
+////            BLed = 1;
+////            RLed = 0;
+//            pc.printf("You are far!\n\r"); while(1) {
+//                    pc.putc(pc.getc() + 1);}
+//            }
           
-           if(abs(acc.getX(faX)) > 1.5 || abs(acc.getZ(faZ)) > 1.3 || abs(acc.getY(faY)) > 0.1)
+           if((abs(acc.getX(faX)) > 1.5 || abs(acc.getZ(faZ)) > 1.3 || abs(acc.getY(faY)) > 0.1) || (distance1<30 && distance2<30)) 
            {
             
             //Red = 0;
 //            Blue = 1;
 //            Green = 1;
-            pc.printf("Going too fast!\n\r"); while(1) {
-            pc.putc(pc.getc() + 1);}
+            
+           // pc.printf("Going too fast!\n\r"); //while(1) {
+           // pc.putc(pc.getc() + 1);}
+            
+            buzzer=buzz_on;
+            wait(0.5);
+            buzzer=buzz_off;
+            wait(0.5);
+            
+            for(led_speed=0; led_speed<=10; led_speed++){
+                bar.setLevel(led_speed);
+                wait(0.001);
+                }
 
             } 
             
@@ -99,8 +114,15 @@
                 //Red = 1;
 //                Green = 0;
 //                Blue = 1;
-                    pc.printf("You are safe!\n\r"); while(1) {
-                    pc.putc(pc.getc() + 1);}
+                     
+                   // pc.printf("You are safe!\n\r"); while(1) {
+//                    pc.putc(pc.getc() + 1);}
+                    
+                for(led_speed=0; led_speed<=10; led_speed++){
+                    bar.setLevel(led_speed);
+                    wait(0.2);
+                    }
+                           
                 };
             wait(1.0f);
         }