This is how to commission a K64f board with a HC05 bluetooth module
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 Timeout response; 00004 00005 DigitalOut green(LED_GREEN); 00006 DigitalOut red(LED_RED); 00007 DigitalIn sw2(SW2); 00008 DigitalIn motion(D7); 00009 Serial pc(USBTX, USBRX ); 00010 00011 Serial blue(PTC15, PTC14); //tx, rx 00012 00013 void Alert() { 00014 printf("TimeOut\n\r"); 00015 green = 1; 00016 red = 0; 00017 int run = 1000; 00018 while(run--){ 00019 blue.putc('F'); 00020 } 00021 printf("Alert Sent\n\r"); 00022 /* 00023 run = 100; 00024 while(run--){ 00025 blue.putc('G'); 00026 } 00027 printf("Turned off\n\r"); 00028 */ 00029 } 00030 00031 00032 int main() 00033 { 00034 int i = 0; 00035 //char r[5] = {'a'}; 00036 char send = 'Z'; 00037 char hold = 'a'; 00038 char correct = 'C'; 00039 00040 pc.baud(9600); 00041 blue.baud(9600); 00042 printf("Master Connecting to Slave:\n\r"); 00043 00044 while (send!='R') { 00045 00046 blue.putc(send); 00047 wait(0.5f); // wait a small period of time 00048 00049 if(blue.readable()) 00050 { 00051 while(hold!='X'){ 00052 hold = blue.getc(); 00053 } 00054 if(hold=='X') 00055 { 00056 printf("Ack Recieved from Slave: Sytem Ready!\n\r"); 00057 send = 'R'; //System Ready 00058 } 00059 } 00060 wait(0.5f); // wait a small period of time 00061 i++; // increment the variable 00062 green = !green; // toggle a led 00063 } 00064 00065 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 00066 while(1) 00067 { 00068 while(motion) 00069 { 00070 printf("Motion Detected\n\r"); 00071 00072 if(sw2==1){ 00073 response.attach(&Alert, 2.0); 00074 blue.putc('A'); 00075 green=0; 00076 red = 0; 00077 } 00078 else{ 00079 printf("Sw2 pressed\n\r"); 00080 response.detach(); 00081 printf("Correct Password\n\r"); 00082 int run = 1000; 00083 while(run--){ 00084 blue.putc(correct); 00085 red = 1; 00086 green = 0; 00087 } 00088 wait(3); 00089 } 00090 } 00091 } 00092 }
Generated on Thu Jul 14 2022 08:10:09 by
1.7.2