Basic Alert Function for K64F with Bluetooth

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Master_Main_Collision.cpp Source File

Master_Main_Collision.cpp

00001 #include "mbed.h"
00002 Timeout response;
00003 
00004 DigitalOut green(LED_GREEN);
00005 DigitalOut red(LED_RED);
00006 DigitalOut led(D6); 
00007 DigitalIn  sw2(SW2);
00008 Serial pc(USBTX, USBRX );
00009 Serial blue(PTC15, PTC14); //tx, rx
00010 
00011 int main()
00012 {
00013     int flag = 0; 
00014     char hold = 'b';
00015     char recieved; 
00016     char send = 'Z';
00017     pc.baud(9600);
00018     blue.baud(9600);
00019     printf("Master connecting to the slave\n");
00020 
00021     while (true) {
00022 
00023         blue.putc(send);
00024         wait(0.5f); // wait a small period of time       
00025 
00026         if(blue.readable())//Determine if there is a character available to read.
00027         {
00028                
00029                //--------------------------Temperature Module-----------------------------
00030                
00031 
00032                 recieved = blue.getc();
00033                 //printf("\n word = %c \n\r", recieved);
00034                 int RANGE = ((recieved) - '0');
00035                 float RANGEFIXED = RANGE; 
00036 
00037                 
00038                 //--------------------------Temperature Module End----------------------------
00039                 
00040                 
00041                 pc.printf("\n Lock Mode: unknown person(s) within = %f Units  \n\r", RANGEFIXED);  
00042                 if(RANGEFIXED < 49)
00043                 {
00044                      pc.printf("\nAlert Triggered\n\r");  
00045                      flag = 1; 
00046              
00047                 }    
00048                 else   
00049                 {
00050                     pc.printf("\n All Clear \n\r"); 
00051                     flag = 0; 
00052                 }
00053                     
00054         }
00055         
00056         if(flag == 1)
00057             for(int timer = 0; timer < 10; timer++)
00058             {
00059                 wait(0.05f); 
00060                 led = !led;
00061             }
00062                 
00063     }
00064 
00065 }