“透传点灯实验”的版本间的差异
第36行: | 第36行: | ||
**LED与电阻串接与GND与D13之间,需注意LED极性。 | **LED与电阻串接与GND与D13之间,需注意LED极性。 | ||
见下图 | 见下图 | ||
− | [[File: | + | [[File:transmission.jpg|600px|center|thumb]] |
==程序== | ==程序== |
2014年10月29日 (三) 16:27的版本
Microduino-Zigbee透传点灯实验
目的本教程展示了Microduino-Zigbee模块的数据透传。发送端为协调器节点,接收端为路由节点。路由节点的LED灯的亮灭受控于协调器端的开关控制,表征了透传的实现。 设备
实验说明
见下图 程序
//sender coordinator this example
#include <SoftwareSerial.h>
String myString="";
String IEEEAD="";
#define keyON 5
#define keyOFF 6
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
pinMode(keyON,INPUT_PULLUP);
pinMode(keyOFF,INPUT_PULLUP);
mySerial.begin(9600);
}
void loop()
{
while (mySerial.available() > 0)
{
myString += char(mySerial.read());
delay(2);
}
if (myString.length() > 0)
{
if(myString[0]=='+'&&myString[7]==','&&myString[12]==',')
{
for(int i=13;i<myString.length();i++)
IEEEAD+=myString[i];
myString="+ZBD=" +IEEEAD;
while(1)
{
if(digitalRead(keyON)==0)
{
delay(50);
if(digitalRead(keyON)==0)
{
mySerial.print(myString);
mySerial.println("ON");
delay(300);
}
}
if(digitalRead(keyOFF)==0)
{
delay(50);
if(digitalRead(keyOFF)==0)
{
mySerial.print(myString);
mySerial.println("OFF");
delay(300);
}
}
}
}
}
}
程序如下 //sender coordinator this example
String myString="";
String IEEEAD="";
#define keyON 5
#define keyOFF 6
void setup()
{
pinMode(keyON,INPUT_PULLUP);
pinMode(keyOFF,INPUT_PULLUP);
Serial1.begin(9600);
}
void loop()
{
while (Serial1.available() > 0)
{
myString += char(Serial1.read());
delay(2);
}
if (myString.length() > 0)
{
if(myString[0]=='+'&&myString[7]==','&&myString[12]==',')
{
for(int i=13;i<myString.length();i++)
IEEEAD+=myString[i];
myString="+ZBD=" +IEEEAD;
while(1)
{
if(digitalRead(keyON)==0)
{
delay(50);
if(digitalRead(keyON)==0)
{
Serial1.print(myString);
Serial1.println("ON");
delay(300);
}
}
if(digitalRead(keyOFF)==0)
{
delay(50);
if(digitalRead(keyOFF)==0)
{
Serial1.print(myString);
Serial1.println("OFF");
delay(300);
}
}
}
}
}
}
// receiver router this example
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
String myString="";
void setup()
{
pinMode(13,OUTPUT);
mySerial.begin(9600);
}
void loop()
{
while (mySerial.available() > 0)
{
myString += char(mySerial.read());
delay(2);
}
if (myString.length() > 0)
{
if(myString=="ON")
digitalWrite(13,HIGH);
if(myString=="OFF")
digitalWrite(13,LOW);
}
myString="";
}
调试
|