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

Dependencies:   mbed

Committer:
YoshihitoShimada
Date:
Mon Jun 01 02:40:04 2015 +0000
Revision:
0:e423d98fecae
Bluetooth test sample program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YoshihitoShimada 0:e423d98fecae 1 #include "mbed.h"
YoshihitoShimada 0:e423d98fecae 2 Serial bluetooth(P0_19, P0_18); //tx, rx
YoshihitoShimada 0:e423d98fecae 3 DigitalOut Light(P0_16);
YoshihitoShimada 0:e423d98fecae 4
YoshihitoShimada 0:e423d98fecae 5 int main() {
YoshihitoShimada 0:e423d98fecae 6 bluetooth.baud(115200);
YoshihitoShimada 0:e423d98fecae 7 int32_t i;
YoshihitoShimada 0:e423d98fecae 8 uint8_t buf;
YoshihitoShimada 0:e423d98fecae 9 char moji[64];
YoshihitoShimada 0:e423d98fecae 10
YoshihitoShimada 0:e423d98fecae 11 Light=0;
YoshihitoShimada 0:e423d98fecae 12
YoshihitoShimada 0:e423d98fecae 13 while (1) {
YoshihitoShimada 0:e423d98fecae 14 if(bluetooth.readable()) {
YoshihitoShimada 0:e423d98fecae 15 i=0;
YoshihitoShimada 0:e423d98fecae 16 do {
YoshihitoShimada 0:e423d98fecae 17 buf=bluetooth.getc();
YoshihitoShimada 0:e423d98fecae 18 moji[i++]=buf;
YoshihitoShimada 0:e423d98fecae 19 } while(buf!='\0');
YoshihitoShimada 0:e423d98fecae 20 buf=moji[0];
YoshihitoShimada 0:e423d98fecae 21 }
YoshihitoShimada 0:e423d98fecae 22 switch (buf){
YoshihitoShimada 0:e423d98fecae 23 case '+': //Light On
YoshihitoShimada 0:e423d98fecae 24 Light=1;
YoshihitoShimada 0:e423d98fecae 25 break;
YoshihitoShimada 0:e423d98fecae 26 case '-': //Light Off
YoshihitoShimada 0:e423d98fecae 27 Light=0;
YoshihitoShimada 0:e423d98fecae 28 break;
YoshihitoShimada 0:e423d98fecae 29 }
YoshihitoShimada 0:e423d98fecae 30 }
YoshihitoShimada 0:e423d98fecae 31 }