Tianyou Tong / Mbed 2 deprecated HM-10_NucleoF401RE_LED_Demo

Dependencies:   SoftSerial mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SoftSerial.h"
00003 
00004 /*Set up serial communication between the HM-10 module and the Nucleo board
00005 For debugging and setting up the module, set up serial between Nucleo and PC
00006 Set up LED for debugging*/
00007 SoftSerial hm10(D3,D2);
00008 Serial pc(USBTX, USBRX);
00009 DigitalOut LED(PA_5);
00010 
00011 char s;
00012 char w;
00013 
00014 void serial_config();
00015 
00016 int main(){
00017     pc.baud(9600);
00018     hm10.baud(9600);//Set up baud rate for serial communication
00019     
00020     while (!hm10.writeable()) { } //wait until the HM10 is ready
00021     
00022     while(1) {
00023         if (hm10.readable())
00024         {  
00025             s = hm10.getc();
00026             pc.putc(s);
00027             if(s == '1'){
00028                 LED = 1;
00029             }
00030             if(s == '0'){
00031                 LED = 0;
00032             }
00033         }
00034         serial_config();
00035     }
00036 } 
00037 
00038 /*serial_config allows you to set up your HM-10 module via USB serial port*/
00039 void serial_config(){
00040     if (pc.readable()){  
00041         w = pc.getc();
00042         hm10.putc(w);
00043     }
00044 }
00045     
00046