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.
Revision 10:47e63d63297f, committed 2020-03-24
- Comitter:
- Jamesan
- Date:
- Tue Mar 24 22:12:49 2020 +0000
- Parent:
- 9:73600707c93b
- Commit message:
- Project 1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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