// 引用 LiquidCrystal
Library
#include <SoftwareSerial.h> // 引用程式庫
#include <LiquidCrystal.h>
// LCD 接腳: rs,
enable, d4, d5, d6, d7
// 對應到 Arduino 接腳:
12, 11, 5,
4, 3, 2
LiquidCrystal lcd(12,
11,5, 4, 3, 2);
String strall="Bluetooth transmission";
String LCD_clear=" ";
SoftwareSerial
BT(8, 9); // 接收腳, 傳送腳
char val;
// 儲存接收資料的變數
void setup() {
lcd.begin(8, 2);//宣告LED 16X1
Serial.begin(115200);//
Serial.begin(9600);
Serial.setTimeout(5);
Serial.println("Bluetooth
transmission started");
BT.begin(38400);
BT.setTimeout(5);
strall="Bluetooth
started"; LCMshow();
}
void loop() {
while (BT.available())
{ //com7 pc keyin
lcd.clear();
strall=BT.readString(); LCMshow();
Serial.println(strall);//BT.readString());
}
while (Serial.available())
{ //com4 keyin
lcd.clear();
strall=Serial.readString(); LCMshow();
BT.println(strall);//Serial.readString());
}
}
int LCMshow()
{
lcd.setCursor(0,
0);//第一行游標
lcd.print(strall.substring(0,8));
lcd.setCursor(0,1);//第二行游標
lcd.print(strall.substring(8,15));
}
int LCMstrrun()
{
lcd.setCursor(0,
0);//第一行游標
lcd.print(" ");
for (int i=0; i<strall.length();
i++)
{ lcd.print(strall.charAt(i)); }
lcd.setCursor(0,
0);//第一行游標
lcd.setCursor(0,1);//第二行游標
//lcd.print(strall.length());
for (int i=0;
i<8 i="" nbsp="" span="">利用常數避免索引超限8>
{ lcd.print(strall.charAt(i)); }
for (int i=8; i<strall.length();
i++)
{ lcd.print(strall.charAt(i)); }
}