トランジスタ技術2015年6月号mbedラジコン・カーp184 リスト4 Bluetoothモジュールのmbedメイン・プログラム

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial bluetooth(P0_19, P0_18); //tx, rx
00003 DigitalOut Light(P0_16);
00004 
00005 int main() {
00006     bluetooth.baud(115200);
00007     int32_t i;
00008     uint8_t buf;
00009     char moji[64];
00010 
00011     Light=0;
00012 
00013     while (1) {
00014         if(bluetooth.readable()) {
00015             i=0;
00016             do {
00017                 buf=bluetooth.getc();
00018                 moji[i++]=buf;
00019             } while(buf!='\0');
00020             buf=moji[0];
00021         }
00022         switch (buf){
00023         case '+':   //Light On
00024             Light=1;
00025             break;
00026         case '-':   //Light Off
00027             Light=0;
00028             break;
00029         }
00030     }
00031 }