Venkata Arza
/
master_Collision
Collision Master for k64f
Master_Main_Collision.cpp
- Committer:
- varza
- Date:
- 2018-12-12
- Revision:
- 0:44a0988d76f6
File content as of revision 0:44a0988d76f6:
#include "mbed.h" Timeout response; DigitalOut green(LED_GREEN); DigitalOut red(LED_RED); DigitalOut led(D6); DigitalIn sw2(SW2); Serial pc(USBTX, USBRX ); Serial blue(PTC15, PTC14); //tx, rx int main() { int flag = 0; char hold = 'b'; char recieved; char send = 'Z'; pc.baud(9600); blue.baud(9600); printf("Master connecting to the slave\n"); while (true) { blue.putc(send); wait(0.5f); // wait a small period of time if(blue.readable())//Determine if there is a character available to read. { //--------------------------Temperature Module----------------------------- recieved = blue.getc(); // printf("\n word = %c \n\r", recieved); int RANGE = ((recieved) - '0'); float RANGEFIXED = RANGE; //--------------------------Temperature Module End---------------------------- pc.printf("\n Distance from collision = %f Units \n\r", RANGEFIXED); if(RANGEFIXED < 50) { pc.printf("\n Auto Brakes: On - LED --> Blue \n\r"); flag = 1; } else { pc.printf("\n Auto Brakes: OFF \n\r"); flag = 0; } } if(flag == 1) for(int timer = 0; timer < 10; timer++) { wait(0.05f); led = !led; } } }