Basic Alert Function for K64F with Bluetooth

Dependencies:   mbed

Committer:
varza
Date:
Wed Dec 12 21:57:58 2018 +0000
Revision:
0:26ab4d6016ae
Alert_Master needed to be combined with Alert_Slave

Who changed what in which revision?

UserRevisionLine numberNew contents of line
varza 0:26ab4d6016ae 1 #include "mbed.h"
varza 0:26ab4d6016ae 2 Timeout response;
varza 0:26ab4d6016ae 3
varza 0:26ab4d6016ae 4 DigitalOut green(LED_GREEN);
varza 0:26ab4d6016ae 5 DigitalOut red(LED_RED);
varza 0:26ab4d6016ae 6 DigitalOut led(D6);
varza 0:26ab4d6016ae 7 DigitalIn sw2(SW2);
varza 0:26ab4d6016ae 8 Serial pc(USBTX, USBRX );
varza 0:26ab4d6016ae 9 Serial blue(PTC15, PTC14); //tx, rx
varza 0:26ab4d6016ae 10
varza 0:26ab4d6016ae 11 int main()
varza 0:26ab4d6016ae 12 {
varza 0:26ab4d6016ae 13 int flag = 0;
varza 0:26ab4d6016ae 14 char hold = 'b';
varza 0:26ab4d6016ae 15 char recieved;
varza 0:26ab4d6016ae 16 char send = 'Z';
varza 0:26ab4d6016ae 17 pc.baud(9600);
varza 0:26ab4d6016ae 18 blue.baud(9600);
varza 0:26ab4d6016ae 19 printf("Master connecting to the slave\n");
varza 0:26ab4d6016ae 20
varza 0:26ab4d6016ae 21 while (true) {
varza 0:26ab4d6016ae 22
varza 0:26ab4d6016ae 23 blue.putc(send);
varza 0:26ab4d6016ae 24 wait(0.5f); // wait a small period of time
varza 0:26ab4d6016ae 25
varza 0:26ab4d6016ae 26 if(blue.readable())//Determine if there is a character available to read.
varza 0:26ab4d6016ae 27 {
varza 0:26ab4d6016ae 28
varza 0:26ab4d6016ae 29 //--------------------------Temperature Module-----------------------------
varza 0:26ab4d6016ae 30
varza 0:26ab4d6016ae 31
varza 0:26ab4d6016ae 32 recieved = blue.getc();
varza 0:26ab4d6016ae 33 //printf("\n word = %c \n\r", recieved);
varza 0:26ab4d6016ae 34 int RANGE = ((recieved) - '0');
varza 0:26ab4d6016ae 35 float RANGEFIXED = RANGE;
varza 0:26ab4d6016ae 36
varza 0:26ab4d6016ae 37
varza 0:26ab4d6016ae 38 //--------------------------Temperature Module End----------------------------
varza 0:26ab4d6016ae 39
varza 0:26ab4d6016ae 40
varza 0:26ab4d6016ae 41 pc.printf("\n Lock Mode: unknown person(s) within = %f Units \n\r", RANGEFIXED);
varza 0:26ab4d6016ae 42 if(RANGEFIXED < 49)
varza 0:26ab4d6016ae 43 {
varza 0:26ab4d6016ae 44 pc.printf("\nAlert Triggered\n\r");
varza 0:26ab4d6016ae 45 flag = 1;
varza 0:26ab4d6016ae 46
varza 0:26ab4d6016ae 47 }
varza 0:26ab4d6016ae 48 else
varza 0:26ab4d6016ae 49 {
varza 0:26ab4d6016ae 50 pc.printf("\n All Clear \n\r");
varza 0:26ab4d6016ae 51 flag = 0;
varza 0:26ab4d6016ae 52 }
varza 0:26ab4d6016ae 53
varza 0:26ab4d6016ae 54 }
varza 0:26ab4d6016ae 55
varza 0:26ab4d6016ae 56 if(flag == 1)
varza 0:26ab4d6016ae 57 for(int timer = 0; timer < 10; timer++)
varza 0:26ab4d6016ae 58 {
varza 0:26ab4d6016ae 59 wait(0.05f);
varza 0:26ab4d6016ae 60 led = !led;
varza 0:26ab4d6016ae 61 }
varza 0:26ab4d6016ae 62
varza 0:26ab4d6016ae 63 }
varza 0:26ab4d6016ae 64
varza 0:26ab4d6016ae 65 }