Nathan Schwartz
/
Home_Base_Station
The code for the home base station.
Fork of HC05_send by
Revision 1:f475551471a5, committed 2018-03-19
- Comitter:
- natschwa
- Date:
- Mon Mar 19 17:24:25 2018 +0000
- Parent:
- 0:c3b88e0b90bf
- Commit message:
- Finished
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Mar 04 23:03:00 2018 +0000 +++ b/main.cpp Mon Mar 19 17:24:25 2018 +0000 @@ -1,92 +1,107 @@ +//Home_System + #include "mbed.h" -Timeout response; +#define RX_ PTC14 +#define TX_ PTC15 + +Timeout response; // Timer -DigitalOut green(LED_GREEN); -DigitalOut red(LED_RED); +//Delay declared in seconds +/*GPIO declaration*/ +DigitalOut Green(LED_GREEN); +DigitalOut Red(LED_RED); +DigitalOut Blue(LED_BLUE); + DigitalIn sw2(SW2); DigitalIn motion(D7); -Serial pc(USBTX, USBRX ); -Serial blue(PTC15, PTC14); //tx, rx +Serial BlueTooth(TX_, RX_); // bluetooth serial port +Serial pc(USBTX, USBRX ); // USB serial port -void Alert() { +void Alert() { // Timer call back function printf("TimeOut\n\r"); - green = 1; - red = 0; - int run = 1000; + Blue = 1; + Green = 1; + Red = 0; + int run = 5000; while(run--){ - blue.putc('F'); + BlueTooth.putc('F'); // send alert to slave } printf("Alert Sent\n\r"); -/* + run = 100; while(run--){ - blue.putc('G'); + BlueTooth.putc('G'); // send alarm timeout to slave } - printf("Turned off\n\r"); -*/ + printf("Alert Timeout\n\r"); + } int main() { - int i = 0; - //char r[5] = {'a'}; char send = 'Z'; char hold = 'a'; char correct = 'C'; + /*LedsOFF (active low)*/ + Red = 1; + Green = 1; + Blue = 1; + pc.baud(9600); - blue.baud(9600); + BlueTooth.baud(9600); printf("Master Connecting to Slave:\n\r"); while (send!='R') { - blue.putc(send); + BlueTooth.putc(send); wait(0.5f); // wait a small period of time - if(blue.readable()) + if(BlueTooth.readable()) // read data from the bluetooth serial port { while(hold!='X'){ - hold = blue.getc(); + hold = BlueTooth.getc(); } if(hold=='X') { printf("Ack Recieved from Slave: Sytem Ready!\n\r"); + Blue = 0; + Red = 1; + Green = 1; send = 'R'; //System Ready } } wait(0.5f); // wait a small period of time - i++; // increment the variable - green = !green; // toggle a led } - ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------- while(1) { - while(motion) - { + while(motion) // detecting motion + { Blue = 1; printf("Motion Detected\n\r"); - if(sw2==1){ - response.attach(&Alert, 2.0); - blue.putc('A'); - green=0; - red = 0; + if(sw2==1){ // use has 2 second window to enter password after motion dection + response.attach(&Alert, 2.0); // set timer for 2 seconds + BlueTooth.putc('A'); // send alert to slave + // LED yellow + Green=0; + Red = 0; } else{ printf("Sw2 pressed\n\r"); - response.detach(); - printf("Correct Password\n\r"); - int run = 1000; + response.detach(); // disable timer + printf("Correct Password\n\r"); + int run = 1000; while(run--){ - blue.putc(correct); - red = 1; - green = 0; + BlueTooth.putc(correct); // send correct password msg to slave + Red = 1; + Green = 0; } wait(3); } } } -} +}//end Main