トランジスタ技術2015年6月号mbedラジコン・カーp184 リスト4 Bluetoothモジュールのmbedメイン・プログラム
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:e423d98fecae
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jun 01 02:40:04 2015 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +Serial bluetooth(P0_19, P0_18); //tx, rx +DigitalOut Light(P0_16); + +int main() { + bluetooth.baud(115200); + int32_t i; + uint8_t buf; + char moji[64]; + + Light=0; + + while (1) { + if(bluetooth.readable()) { + i=0; + do { + buf=bluetooth.getc(); + moji[i++]=buf; + } while(buf!='\0'); + buf=moji[0]; + } + switch (buf){ + case '+': //Light On + Light=1; + break; + case '-': //Light Off + Light=0; + break; + } + } +}