simple hello world on BLE serial communication

Dependencies:   mbed

main.cpp

Committer:
zchen78
Date:
2014-03-16
Revision:
0:2c1acb156d86

File content as of revision 0:2c1acb156d86:

#include "mbed.h"
#include "ble_mini.h"
Serial pc(USBTX, USBRX); // tx, rx
Serial device(p13,p14);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

char buf[10];

int main() {
    int i=0;
    //set mbed baud rate the same as BLE mini baud rate
    device.baud(57600);
    //simple polling demonstrate serial communication
    while(1) {
        if(device.readable()) {
            buf[i]=device.getc();
            if(buf[i]==ON_INTERNEL_LED1)myled1=1;
            if(buf[i]==OFF_INTERNEL_LED1)myled1=0;
            
            if(buf[i]==ON_INTERNEL_LED2)myled2=1;
            if(buf[i]==OFF_INTERNEL_LED2)myled2=0;            
            
            if(buf[i]==ON_INTERNEL_LED3)myled3=1;
            if(buf[i]==OFF_INTERNEL_LED3)myled3=0;            
            
            if(buf[i]==ON_INTERNEL_LED4)myled4=1;
            if(buf[i]==OFF_INTERNEL_LED4)myled4=0;
            
            
            
            
            
            
            i++;  
        }
        
        if(i==10)i=0;
        wait(0.1);
    }
}