Part3.5 傳送五筆資料
===================================================================
#include <SoftwareSerial.h>
SoftwareSerial BT(3,2); // RX, TX
byte cmd;
byte a,b,c,d,e; //此代表待傳送的五個變數
byte Data[16];
void setup() {
Serial.begin(9600);
BT.begin(38400);//bluetooth baud rate
}
void loop() {
a = analogRead(A0);
b = analogRead(A1);
c = analogRead(A2);
d = analogRead(A3);
e = analogRead(A4);
bt();
delay(10); //傳送速度極限大約10ms 一組資料
}
void bt(){
cmd = BT.read();
Data[0]='a';
Data[1]=a/256;
Data[2]=a%256;
Data[3]='b';
Data[4]=b/256;
Data[5]=b%256;
Data[6]='c';
Data[7]=c/256;
Data[8]=c%256;
Data[9]='d';
Data[10]=d/256;
Data[11]=d%256;
Data[12]='e';
Data[13]=e/256;
Data[14]=e%256;
if (cmd == 49){
for(int j=0;j<15;j++){
BT.write(Data[j]);
}
cmd=0;
}
}