Annu James
/
Blue_ultra
Test_bluetooth
Diff: main.cpp
- Revision:
- 10:47e63d63297f
- Parent:
- 9:73600707c93b
--- a/main.cpp Mon Mar 02 17:36:12 2020 +0000 +++ b/main.cpp Tue Mar 24 22:12:49 2020 +0000 @@ -1,34 +1,112 @@ #include "mbed.h" +#include <stdio.h> +#include <string.h> #include "hcsr04.h" Serial pc(USBTX,USBRX); //Serial UART(USBTX,USBRX); HCSR04 usensor(D8,D12); //Bluetooth module declaration -Serial HC06(PTC17,PTC16); //BT TX RX -char snd[512],rcv[1000]; +Serial blue(PTC15, PTC14); +DigitalOut Redl(LED1); +DigitalOut Bluel(LED3); +DigitalOut Greenl(LED2); + +DigitalOut vibMotorR(D3); +DigitalOut vibMotorL(D5); + +int c =0; unsigned int dist; char a; - +char k; Timer dt; - int main() { pc.baud(9600); - unsigned char rx; dt.start(); - while(1) { - usensor.start(); + Greenl = 1; //FRDM LED initially OFF + Bluel = 1; //FRDM LED initially OFF + Redl = 1; //FRDM LED initially OFF + vibMotorL = 0; + vibMotorR = 0; + while(1) + { + usensor.start(); wait_ms(500); - pc.printf("started"); - rx = HC06.getc(); - pc.printf("\n\r %ld",rx); dist=usensor.get_dist_cm(); - dt.reset(); - if(dist>1 and dist<=30) - { - pc.printf("case: 1\r\n"); - pc.printf("\n\r %ld",dist ); - } - } -} \ No newline at end of file + printf("\n\r cm:%ld",dist); + dt.reset(); + k = 'F'; + if(blue.readable()> 0) + { + c = blue.getc(); + pc.printf("\n\rbluetooth"); + pc.printf("\n\r %ld",c); + k = 'T'; + } + if(dist>1 and dist<=30) + { + pc.printf("case1: Obstacle ahead\r\n"); + pc.printf("\n\r %ld",dist); + blue.printf("1"); + Redl = 0; + vibMotorL = 1; + vibMotorR = 1; + wait(3); + Redl = 1; + vibMotorL = 0; + vibMotorR = 0; + } + if (k == 'T') + { + if (c == 49) + { + pc.printf("case 2: Turn Left\r\n"); + Greenl = 0; + vibMotorL = 1; + wait(3); + Greenl = 1; + vibMotorL = 0; + k = 'F'; + } + else if (c == 50) + { + pc.printf("case 3: Turn Right\r\n"); + Bluel = 0; + vibMotorR = 1; + wait(3); + Bluel = 1; + vibMotorR = 0; + k = 'F'; + } + else if (c == 51) + { + pc.printf("case 4: Destination reached\r\n"); + Bluel = 0; + Greenl = 0; + Redl = 0; + vibMotorL = 1; + vibMotorR = 1; + wait(3); + Bluel = 1; + Greenl = 1; + Redl = 1; + vibMotorL = 0; + vibMotorR = 0; + wait(1); + Bluel = 0; + Greenl = 0; + Redl = 0; + vibMotorL = 1; + vibMotorR = 1; + wait(3); + Bluel = 1; + Greenl = 1; + Redl = 1; + vibMotorL = 0; + vibMotorR = 0; + k = 'F'; + } + } + } + } \ No newline at end of file