Advertisement
gha890826

send_word

Sep 29th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #include <Wire.h>  //引用二個函式庫SoftwareSerial及Wire SoftwareSerial
  3. SoftwareSerial I2CBT(10,11); //定義PIN10及PIN11分別為RX及TX腳位
  4.  
  5. void setup() {
  6.   Serial.begin(9600); //Arduino起始鮑率9600
  7.   I2CBT.begin(57600); //藍牙鮑率57600
  8.   //(注意!此鮑率每個藍牙晶片不一定相同,請先確認完再填寫進去)
  9. }
  10.  
  11. void loop() {
  12.   byte cmmd[20];
  13.   int insize;
  14.   while(1){
  15.   if ((insize=(I2CBT.available()))>0)
  16.   {  //判斷有沒有訊息接收
  17.     Serial.print("input size = ");
  18.     Serial.println(insize);  //顯示接收多少訊息
  19.     for (int i=0; i<insize; i++) {
  20.       Serial.print(cmmd[i]=char(I2CBT.read()));//將接收的訊息顯示出來
  21.       Serial.println(" ");  
  22.     }//if
  23.    
  24.     Serial.print("end one time\n");
  25.   } //for
  26.   }//while
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement