代码编号:BT_softwareSerial_0
[code]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 8); // RX, TX
int cnt = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
mySerial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
mySerial.print("Message:");
delay(1000);
mySerial.println(cnt);
delay(5000);
}
[/code]
=========================================================================
代码编号: BT_softwareSerial_1
[code]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 8); // RX, TX
int cnt = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
mySerial.begin(9600);
}
void loop() {
// 虚拟串口向手机发送数据
mySerial.print("Message:");
delay(1000);
mySerial.println(cnt);
delay(5000);
if(mySerial.available() ) //条件满足说明虚拟串口有未读数据
{
unsigned char inChar = mySerial.read();
Serial.write(inChar);
cnt++; //收到一个字符,计数值加一
}
}
[/code]
=======================================================================
代码编号:BT_AT
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 8); // RX, TX
int cnt = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
mySerial.begin(9600);
}
void loop() {
// 虚拟串口向手机发送数据
mySerial.println("AT"); //可以在这指令后面继续添加你需要的AT指令
if(mySerial.available() ) //条件满足说明虚拟串口有未读数据
{
unsigned char inChar = mySerial.read();
Serial.write(inChar);
}
delay(1000);
}