Zeheng Chen / Mbed 2 deprecated Serial_BLE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ble_mini.h"
00003 Serial pc(USBTX, USBRX); // tx, rx
00004 Serial device(p13,p14);
00005 DigitalOut myled1(LED1);
00006 DigitalOut myled2(LED2);
00007 DigitalOut myled3(LED3);
00008 DigitalOut myled4(LED4);
00009 
00010 char buf[10];
00011 
00012 int main() {
00013     int i=0;
00014     //set mbed baud rate the same as BLE mini baud rate
00015     device.baud(57600);
00016     //simple polling demonstrate serial communication
00017     while(1) {
00018         if(device.readable()) {
00019             buf[i]=device.getc();
00020             if(buf[i]==ON_INTERNEL_LED1)myled1=1;
00021             if(buf[i]==OFF_INTERNEL_LED1)myled1=0;
00022             
00023             if(buf[i]==ON_INTERNEL_LED2)myled2=1;
00024             if(buf[i]==OFF_INTERNEL_LED2)myled2=0;            
00025             
00026             if(buf[i]==ON_INTERNEL_LED3)myled3=1;
00027             if(buf[i]==OFF_INTERNEL_LED3)myled3=0;            
00028             
00029             if(buf[i]==ON_INTERNEL_LED4)myled4=1;
00030             if(buf[i]==OFF_INTERNEL_LED4)myled4=0;
00031             
00032             
00033             
00034             
00035             
00036             
00037             i++;  
00038         }
00039         
00040         if(i==10)i=0;
00041         wait(0.1);
00042     }
00043 }