ربط الدائرة
كود البرمجة
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); //TX, RX respetively
String device;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
//-----------------------------------------------------------------------//
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
device += c; //build the string.
}
if (device.length() > 0) {
Serial.println(device);
if(device == "1")
{
digitalWrite(3, HIGH);
}
else if(device == "2")
{
digitalWrite(3, LOW);
}
else if (device == "3")
{
digitalWrite (4,HIGH);
}
else if ( device == "4")
{
digitalWrite (4, LOW);
}
else if (device == "5")
{
digitalWrite (5, HIGH);
}
else if (device == "6")
{
digitalWrite (5, LOW);
}
else if (device == "7")
{
digitalWrite (6, HIGH);
}
else if (device == "8")
{
digitalWrite (6, LOW);
}
else if (device == "9")
{
digitalWrite (7, HIGH);
}
else if (device == "10")
{
digitalWrite (7, LOW);
}
else if (device == "11")
{
digitalWrite (8, HIGH);
}
else if (device == "12")
{
digitalWrite (8, LOW);
}
else if (device == "13")
{
digitalWrite (9, HIGH);
}
else if (device == "14")
{
digitalWrite (9, LOW);
}
else if (device == "15")
{
digitalWrite (12, HIGH);
}
else if (device == "17")
{
digitalWrite (12, LOW);
}
else if (device == "16")
{
digitalWrite (13, HIGH);
}
else if (device == "18")
{
digitalWrite (13, LOW);
}
device="";}} //Reset the variable