ผมจะลองทดสอบการรับ Bluetooth (ด้วย Bluetooth module ที่เชื่อมต่อกับ Arduino ) แล้วทำให้ไฟ Arduino ติด เมื่อใส่ 1 เข้าไป จะต้องไปแก้โค้ดตรงไหนครับ
[open_code]
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int LED = 13;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
if(bluetooth.available())
{
char toSend = (char)bluetooth.read();
if(toSend == '0') {
digitalWrite(LED, LOW); // if 1, switch LED Off
Serial.println("LED OFF. Press 1 to LED ON!"); // print message
}
if(toSend == '1') {
digitalWrite(LED, HIGH); // if 0, switch LED on
Serial.println("LED ON. Press 0 to LED OFF!");
}
}
}
[/close_code]
ผมได้ลองเพิ่ม
[open_code]
boolean bluetooth.available()=true;
boolean bluetooth.read()=true;
char toSend='1';
[/close_code]
ต่อจากบรรทัด int LED = 13;
มัน Error ขึ้นว่า error: expected initializer before ‘.’ token ตรง
[open_code]
bluetooth.available()=true;
boolean bluetooth.read()=true;
[/close_code]
ต้องการทดสอบการรับ Bluetooth (ด้วย Bluetooth module ที่เชื่อมต่อกับ Arduino ) แต่ไม่รู้จะแก้โค้ดยังไง
[open_code]
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int LED = 13;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
if(bluetooth.available())
{
char toSend = (char)bluetooth.read();
if(toSend == '0') {
digitalWrite(LED, LOW); // if 1, switch LED Off
Serial.println("LED OFF. Press 1 to LED ON!"); // print message
}
if(toSend == '1') {
digitalWrite(LED, HIGH); // if 0, switch LED on
Serial.println("LED ON. Press 0 to LED OFF!");
}
}
}
[/close_code]
ผมได้ลองเพิ่ม
[open_code]
boolean bluetooth.available()=true;
boolean bluetooth.read()=true;
char toSend='1';
[/close_code]
ต่อจากบรรทัด int LED = 13;
มัน Error ขึ้นว่า error: expected initializer before ‘.’ token ตรง
[open_code]
bluetooth.available()=true;
boolean bluetooth.read()=true;
[/close_code]