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: mbed-os FXAS21000 LED_Bar FXOS8700Q
Revision 4:91893b37450e, committed 2022-04-27
- Comitter:
- mukundy8
- Date:
- Wed Apr 27 00:22:09 2022 +0000
- Parent:
- 3:9ab65e6d4cd4
- Commit message:
- final;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 26 23:07:20 2022 +0000
+++ b/main.cpp Wed Apr 27 00:22:09 2022 +0000
@@ -3,6 +3,26 @@
#include "FXAS21000.h"
#include "hcsr04.h"
#include "LED_Bar.h"
+#include <stdio.h>
+#include <string.h>
+//Colours for printf
+#define cyan "\033[0;36m" /* 0 -> normal; 36 -> cyan */
+#define green "\033[4;32m" /*4 -> underline ; 32 -> green */
+#define blue "\033[9;34m" /*9 -> strike ; 34 -> blue */
+#define KWHT "\x1B[37m"
+#define none "\033[0m" /* to flush the previous property */
+
+//IO declarations
+Serial pc(USBTX, USBRX); //PC UART
+//DigitalOut led1(LED1);
+DigitalOut GREEN(LED2); //Input Mode
+DigitalOut BLUE(LED3); //output mode
+DigitalIn sw2(SW2); //INPUT MODE SELECT
+DigitalIn sw3(SW3); //Output mode select
+//Bluetooth module declaration
+Serial HC06(PTC15, PTC14); //BT TX, RX
+char snd[512], rcv[1000]; //send and receive buffer
+
I2C i2c(PTE25, PTE24);
Serial pc(USBTX,USBRX);
FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors
@@ -32,6 +52,8 @@
int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int;
acc.enable();
mag.enable();
+ usensor1.start();
+ wait_ms(500);
//DigitalOut Red(LED1);
// Red=1;
// DigitalOut Blue(LED3);
@@ -64,18 +86,17 @@
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) {
+ // if (distance1<30 && distance2<30) {
+////
+ // pc.printf("You are colse!\n\r");}
// pc.putc(pc.getc() + 1);}
// //printf("Percent remaining: %f\r", dist_percent1 && dist_percent2);
// } else {
@@ -86,7 +107,7 @@
// pc.putc(pc.getc() + 1);}
// }
- if((abs(acc.getX(faX)) > 1.5 || abs(acc.getZ(faZ)) > 1.3 || abs(acc.getY(faY)) > 0.1) || (distance1<30 && distance2<30))
+ 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;
@@ -105,6 +126,9 @@
bar.setLevel(led_speed);
wait(0.001);
}
+
+ HC06.printf("\nWe are in danger, sending sms now\n");
+\
}
@@ -115,12 +139,12 @@
// Green = 0;
// Blue = 1;
- // pc.printf("You are safe!\n\r"); while(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);
}
};