dad

Dependencies:   mbed-os FXAS21000 LED_Bar FXOS8700Q

Committer:
mukundy8
Date:
Tue Apr 26 21:26:04 2022 +0000
Revision:
2:d08625231a9f
Parent:
1:7a49fd0692fd
Child:
3:9ab65e6d4cd4
final project first

Who changed what in which revision?

UserRevisionLine numberNew contents of line
priyank12p 0:838685d68d89 1 #include "mbed.h"
priyank12p 0:838685d68d89 2 #include "FXOS8700Q.h"
priyank12p 0:838685d68d89 3 #include "FXAS21000.h"
mukundy8 2:d08625231a9f 4 #include "hcsr04.h"
priyank12p 0:838685d68d89 5 I2C i2c(PTE25, PTE24);
priyank12p 0:838685d68d89 6 Serial pc(USBTX,USBRX);
priyank12p 0:838685d68d89 7 FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors
priyank12p 0:838685d68d89 8 FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
priyank12p 0:838685d68d89 9 FXAS21000 gyro(D14,D15);
mukundy8 2:d08625231a9f 10 HCSR04 usensor1(D8,D9); //ECHO Pin=D9, TRIG Pin=D8
mukundy8 2:d08625231a9f 11 HCSR04 usensor2(D7,D6); //ECHO Pin=D7, TRIG Pin=D6
mukundy8 2:d08625231a9f 12
priyank12p 0:838685d68d89 13 int main(void)
priyank12p 0:838685d68d89 14 {
mukundy8 2:d08625231a9f 15 int num = 0;
mukundy8 2:d08625231a9f 16 int distance1, distance2;
mukundy8 2:d08625231a9f 17 float dist_remaining1, dist_percent1, dist_remaining2, dist_percent2;
mukundy8 2:d08625231a9f 18 char snd[255],rcv[1000]; //snd: send command to ESP8266
mukundy8 2:d08625231a9f 19 //rcv: receive response from ESP8266
mukundy8 2:d08625231a9f 20
mukundy8 2:d08625231a9f 21 //Ultrasound Sensor (HC-SR04) #1 Initialization
mukundy8 2:d08625231a9f 22 int a = 30;
mukundy8 2:d08625231a9f 23 usensor1.start();
mukundy8 2:d08625231a9f 24 wait_ms(500);
mukundy8 2:d08625231a9f 25
mukundy8 2:d08625231a9f 26 //Calculating Distance Percentage Remaining for Sensor # 1
mukundy8 2:d08625231a9f 27 distance1 = usensor1.get_dist_cm();
mukundy8 2:d08625231a9f 28 dist_remaining1 = a-distance1;
mukundy8 2:d08625231a9f 29 dist_percent1 = (dist_remaining1/30)*100;
mukundy8 2:d08625231a9f 30
mukundy8 2:d08625231a9f 31 //LED and Tera Term Output
mukundy8 2:d08625231a9f 32 if (distance1<30 && distance2<30) {
mukundy8 2:d08625231a9f 33 //RLed = 1;
mukundy8 2:d08625231a9f 34 // BLed = 1;
mukundy8 2:d08625231a9f 35 // GLed = 0;
mukundy8 2:d08625231a9f 36 pc.printf("You are colse!\n\r"); while(1) {
mukundy8 2:d08625231a9f 37 pc.putc(pc.getc() + 1);}
mukundy8 2:d08625231a9f 38 //printf("Percent remaining: %f\r", dist_percent1 && dist_percent2);
mukundy8 2:d08625231a9f 39 } else {
mukundy8 2:d08625231a9f 40 //GLed = 1;
mukundy8 2:d08625231a9f 41 // BLed = 1;
mukundy8 2:d08625231a9f 42 // RLed = 0;
mukundy8 2:d08625231a9f 43 pc.printf("You are far!\n\r"); while(1) {
mukundy8 2:d08625231a9f 44 pc.putc(pc.getc() + 1);}
mukundy8 2:d08625231a9f 45 }
priyank12p 0:838685d68d89 46 float gyro_data[3];
priyank12p 0:838685d68d89 47 motion_data_units_t acc_data, mag_data;
priyank12p 0:838685d68d89 48 motion_data_counts_t acc_raw, mag_raw;
priyank12p 0:838685d68d89 49 float faX, faY, faZ, fmX, fmY, fmZ, tmp_float;
priyank12p 0:838685d68d89 50 int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int;
priyank12p 0:838685d68d89 51 acc.enable();
priyank12p 0:838685d68d89 52 mag.enable();
mukundy8 1:7a49fd0692fd 53 DigitalOut Red(LED1);
mukundy8 1:7a49fd0692fd 54 Red=1;
mukundy8 1:7a49fd0692fd 55 DigitalOut Blue(LED3);
mukundy8 1:7a49fd0692fd 56 DigitalOut Green(LED2);
mukundy8 1:7a49fd0692fd 57 Blue=1;
mukundy8 1:7a49fd0692fd 58 Green=1;
mukundy8 1:7a49fd0692fd 59
priyank12p 0:838685d68d89 60 while (true) {
priyank12p 0:838685d68d89 61 // counts based results
priyank12p 0:838685d68d89 62 acc.getAxis(acc_raw);
priyank12p 0:838685d68d89 63 mag.getAxis(mag_raw);
priyank12p 0:838685d68d89 64 acc.getX(raX);
priyank12p 0:838685d68d89 65 acc.getY(raY);
priyank12p 0:838685d68d89 66 acc.getZ(raZ);
priyank12p 0:838685d68d89 67 mag.getX(rmX);
priyank12p 0:838685d68d89 68 mag.getY(rmY);
priyank12p 0:838685d68d89 69 mag.getZ(rmZ);
priyank12p 0:838685d68d89 70 // unit based results
priyank12p 0:838685d68d89 71 acc.getAxis(acc_data);
priyank12p 0:838685d68d89 72 mag.getAxis(mag_data);
priyank12p 0:838685d68d89 73 acc.getX(faX);
priyank12p 0:838685d68d89 74 acc.getY(faY);
priyank12p 0:838685d68d89 75 acc.getZ(faZ);
priyank12p 0:838685d68d89 76 mag.getX(fmX);
priyank12p 0:838685d68d89 77 mag.getY(fmY);
priyank12p 0:838685d68d89 78 mag.getZ(fmZ);
mukundy8 1:7a49fd0692fd 79 pc.printf("FXOSQ8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f", acc.getX(faX),acc.getY(faY),acc.getZ(faZ));
mukundy8 1:7a49fd0692fd 80 pc.printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag.getX(fmX),mag.getY(fmY), mag.getZ(fmZ));
priyank12p 0:838685d68d89 81 gyro.ReadXYZ(gyro_data);
mukundy8 1:7a49fd0692fd 82 pc.printf("FXAS21000 Gyro: X=%6.2f Y=%6.2f Z=%6.2f\r\n", gyro_data[0],gyro_data[1], gyro_data[2]);
mukundy8 1:7a49fd0692fd 83
mukundy8 1:7a49fd0692fd 84
mukundy8 1:7a49fd0692fd 85 if(abs(acc.getX(faX)) > 1.5 || abs(acc.getZ(faZ)) > 1.3 || abs(acc.getY(faY)) > 0.1)
mukundy8 1:7a49fd0692fd 86 {
mukundy8 1:7a49fd0692fd 87
mukundy8 2:d08625231a9f 88 //Red = 0;
mukundy8 2:d08625231a9f 89 // Blue = 1;
mukundy8 2:d08625231a9f 90 // Green = 1;
mukundy8 2:d08625231a9f 91 pc.printf("Going too fast!\n\r"); while(1) {
mukundy8 2:d08625231a9f 92 pc.putc(pc.getc() + 1);}
mukundy8 1:7a49fd0692fd 93
mukundy8 1:7a49fd0692fd 94 }
mukundy8 1:7a49fd0692fd 95
mukundy8 1:7a49fd0692fd 96
mukundy8 1:7a49fd0692fd 97 else{
mukundy8 1:7a49fd0692fd 98
mukundy8 2:d08625231a9f 99 //Red = 1;
mukundy8 2:d08625231a9f 100 // Green = 0;
mukundy8 2:d08625231a9f 101 // Blue = 1;
mukundy8 2:d08625231a9f 102 pc.printf("You are safe!\n\r"); while(1) {
mukundy8 2:d08625231a9f 103 pc.putc(pc.getc() + 1);}
mukundy8 1:7a49fd0692fd 104 };
priyank12p 0:838685d68d89 105 wait(1.0f);
priyank12p 0:838685d68d89 106 }
priyank12p 0:838685d68d89 107 }