Venkata Arza
/
master_Collision
Collision Master for k64f
Master_Main_Collision.cpp@0:44a0988d76f6, 2018-12-12 (annotated)
- Committer:
- varza
- Date:
- Wed Dec 12 22:02:04 2018 +0000
- Revision:
- 0:44a0988d76f6
master collision;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
varza | 0:44a0988d76f6 | 1 | #include "mbed.h" |
varza | 0:44a0988d76f6 | 2 | Timeout response; |
varza | 0:44a0988d76f6 | 3 | |
varza | 0:44a0988d76f6 | 4 | DigitalOut green(LED_GREEN); |
varza | 0:44a0988d76f6 | 5 | DigitalOut red(LED_RED); |
varza | 0:44a0988d76f6 | 6 | DigitalOut led(D6); |
varza | 0:44a0988d76f6 | 7 | DigitalIn sw2(SW2); |
varza | 0:44a0988d76f6 | 8 | Serial pc(USBTX, USBRX ); |
varza | 0:44a0988d76f6 | 9 | Serial blue(PTC15, PTC14); //tx, rx |
varza | 0:44a0988d76f6 | 10 | |
varza | 0:44a0988d76f6 | 11 | int main() |
varza | 0:44a0988d76f6 | 12 | { |
varza | 0:44a0988d76f6 | 13 | int flag = 0; |
varza | 0:44a0988d76f6 | 14 | char hold = 'b'; |
varza | 0:44a0988d76f6 | 15 | char recieved; |
varza | 0:44a0988d76f6 | 16 | char send = 'Z'; |
varza | 0:44a0988d76f6 | 17 | pc.baud(9600); |
varza | 0:44a0988d76f6 | 18 | blue.baud(9600); |
varza | 0:44a0988d76f6 | 19 | printf("Master connecting to the slave\n"); |
varza | 0:44a0988d76f6 | 20 | |
varza | 0:44a0988d76f6 | 21 | while (true) { |
varza | 0:44a0988d76f6 | 22 | |
varza | 0:44a0988d76f6 | 23 | blue.putc(send); |
varza | 0:44a0988d76f6 | 24 | wait(0.5f); // wait a small period of time |
varza | 0:44a0988d76f6 | 25 | |
varza | 0:44a0988d76f6 | 26 | if(blue.readable())//Determine if there is a character available to read. |
varza | 0:44a0988d76f6 | 27 | { |
varza | 0:44a0988d76f6 | 28 | |
varza | 0:44a0988d76f6 | 29 | //--------------------------Temperature Module----------------------------- |
varza | 0:44a0988d76f6 | 30 | |
varza | 0:44a0988d76f6 | 31 | |
varza | 0:44a0988d76f6 | 32 | recieved = blue.getc(); |
varza | 0:44a0988d76f6 | 33 | // printf("\n word = %c \n\r", recieved); |
varza | 0:44a0988d76f6 | 34 | int RANGE = ((recieved) - '0'); |
varza | 0:44a0988d76f6 | 35 | float RANGEFIXED = RANGE; |
varza | 0:44a0988d76f6 | 36 | |
varza | 0:44a0988d76f6 | 37 | |
varza | 0:44a0988d76f6 | 38 | //--------------------------Temperature Module End---------------------------- |
varza | 0:44a0988d76f6 | 39 | |
varza | 0:44a0988d76f6 | 40 | |
varza | 0:44a0988d76f6 | 41 | pc.printf("\n Distance from collision = %f Units \n\r", RANGEFIXED); |
varza | 0:44a0988d76f6 | 42 | if(RANGEFIXED < 50) |
varza | 0:44a0988d76f6 | 43 | { |
varza | 0:44a0988d76f6 | 44 | pc.printf("\n Auto Brakes: On - LED --> Blue \n\r"); |
varza | 0:44a0988d76f6 | 45 | flag = 1; |
varza | 0:44a0988d76f6 | 46 | |
varza | 0:44a0988d76f6 | 47 | } |
varza | 0:44a0988d76f6 | 48 | else |
varza | 0:44a0988d76f6 | 49 | { |
varza | 0:44a0988d76f6 | 50 | pc.printf("\n Auto Brakes: OFF \n\r"); |
varza | 0:44a0988d76f6 | 51 | flag = 0; |
varza | 0:44a0988d76f6 | 52 | } |
varza | 0:44a0988d76f6 | 53 | |
varza | 0:44a0988d76f6 | 54 | } |
varza | 0:44a0988d76f6 | 55 | |
varza | 0:44a0988d76f6 | 56 | if(flag == 1) |
varza | 0:44a0988d76f6 | 57 | for(int timer = 0; timer < 10; timer++) |
varza | 0:44a0988d76f6 | 58 | { |
varza | 0:44a0988d76f6 | 59 | wait(0.05f); |
varza | 0:44a0988d76f6 | 60 | led = !led; |
varza | 0:44a0988d76f6 | 61 | } |
varza | 0:44a0988d76f6 | 62 | |
varza | 0:44a0988d76f6 | 63 | } |
varza | 0:44a0988d76f6 | 64 | |
varza | 0:44a0988d76f6 | 65 | } |