Arduino 433 + 串口
http://www.freebuf.com/articles/wireless/105398.html
/*本作品使用的例程中包含RCSwitch库文件用于信号的解码和编码发送*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
//串口打印命令帮助信息
Serial.print("HELP:A-flash the lamp A\n B-flash the lamp B\n C-flash the lamp C\n D-flash the lamp D\n");
Serial.print(" a-open the lamp A\n b-open the lamp B\n c-open the lamp C\n d-open the lamp D\n\n");
mySwitch.enableReceive(1);
mySwitch.enableTransmit(10);}2
void loop()
{
if(mySwitch.available())
{
output(mySwitch.getReceivedValue(),mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(),mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
/* Same switch as above,but using binary code */
if(Serial.available()>0)//如果串口有数据进入的话
{ delay(10); //延时50 可以一次性发送多个命令
char M=Serial.read();//每次读一个字符,是ASCII码的
if(M=='A')
{
Serial.print("Thecommand is A\n");
mySwitch.send("010101010101010100001100");//遥控器-A
Serial.print(" OK!!! The LED A has been DONE\n");
}
if(M=='a')
{
Serial.print("The command is a\n");
Serial.print(" OK!!! TheLED A has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100001100");//遥控器-A 按下不放
}
}
if(M=='B')
{
Serial.print("Thecommand is B\n");
mySwitch.send("010101010101010111000000");//遥控器-B
Serial.print(" OK!!! The LED B has been DONE\n");
}
if(M=='b')
{
Serial.print("The command is b\n");
Serial.print(" OK!!! The LED B has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010111000000");//遥控器-B 按下不放
}
}
if(M=='C')
{
Serial.print("Thecommand is C\n");
mySwitch.send("010101010101010100000011");//遥控器-C
Serial.print(" OK!!! The LED C has been DONE\n");
}
if(M=='c')
{
Serial.print("The command is c\n");
Serial.print(" OK!!! TheLED C has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100000011");//遥控器-C按下不放
}
}
if(M=='D')
{
Serial.print("Thecommand is D\n");
mySwitch.send("010101010101010100110000");//遥控器-D
Serial.print(" OK!!! The LED D has been DONE\n");
}
if(M=='d')
{
Serial.print("The command is d\n");
Serial.print(" OK!!! TheLED D has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100110000");//遥控器-D按下不放
}
}
}
}
Arduino 433 + 串口的更多相关文章
- C#与Arduino通过串口通信来控制LED灯的状态
一.引言 最近摆弄了一段时间的Arduino,发现Arduino做一些电子类项目.监控.机器人.电子玩具比较容易,并且Arduino与.NET程序集成也不难.接下来介绍一个简单的小程序,C#做的一个W ...
- 手机与Arduino蓝牙串口通讯实验及完整例程
安卓手机与Arduino之间采用蓝牙串口通讯,是很多智能装置和互动装置常用的控制方法,简单而有效,无需网络环境,很实用的技术. 实验采用Arduino UNO板,加了一块1602LCD屏做显示(因为只 ...
- 关于arduino清空串口缓存(转)
在arduino1.0之前的版本 Serial.flush()的作用是是清空串口缓存( dropping received incoming data).但在1.0之后的版本 Serial.flush ...
- 【ARDUINO】串口无法打开问题
1.查看是否串口被锁 sudo arduino ls /var/lock sudo rm /var/lock/LCK..ttyACM* 2.查看arduino安装位置 dpkg -S XXXX 3.原 ...
- Arduino通过串口监视器收发数据
在串口监视器中发送数据,板子收到数据并打印出来. 不需要额外电路,但是板子必须连接电脑,Arduino IDE的串口监视器也需要被打开. 代码 /* 串口事件 当新的串口数据到来时,我们会将它添加到一 ...
- Arduino在串口监视器上输出字母表
程序会在Arduino IDE的串口监视器上输出一个字母表. 不需要额外电路,但是板子必须通过串口线或USB线连接到电脑. 代码 程序在setup()函数中建立串口连接,然后逐行输出a~z的字母I表, ...
- Arduino通讯串口
串口是Arduino与其它设备进行通信的接口 所有的Arduino控制板有至少一个串口(又称作为UART或USART).它通过0(RX)和1(TX)数字引脚经过串口转换芯片连接计算机USB端口与计算机 ...
- [Arduino] 在串口读取多个字符串,并且转换为数字数组
功能如题目.在串口收到逗号分割的6串数字比如100,200,45,4,87,99然后在6个PWM端口3, 5, 6, 9, 10, 11输出对应PWM值代码注释很详细了,就不再说明了. //定义一个c ...
- PMS5003ST+Arduino Nano 串口读取数据
先上代码: 库文件是在guihub上的大神写的https://github.com/jbanaszczyk,我拿来小改下用以支持5003ST #include <Arduino.h> #i ...
随机推荐
- 4.数码相框-freetype多行显示,居中显示
本章主要内容如下: 1)多行显示 2)居中显示 在上章3.数码相框-通过freetype库实现矢量显示里,我们使用矢量坐标时,该坐标仅仅在原点位置处,所以文字有可能会超出坐标,如下图所示: 既然超出了 ...
- Bell(hdu4767+矩阵+中国剩余定理+bell数+Stirling数+欧几里德)
Bell Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- IOC容器的创建
一.IOC容器创建方式 Ioc容器的创建时通过ApplicationContext接口的相关实现类进行的. 如上图所示:有三种创建IOC容器的方式. ClassPathXmlApplicationCo ...
- Django Rest Framework之解析器
基本代码结构 urls.py: from django.conf.urls import url, include from web.views.s5_parser import TestView u ...
- LoadRunner接口测试标准模板
Action() { int nHttpRetCode; // 默认最大长度为256,get请求需注意缓存问题,需要根据content-length进行修改 web_set_max_html_para ...
- python爬虫入门---第二篇:获取2019年中国大学排名
我们需要爬取的网站:最好大学网 我们需要爬取的内容即为该网页中的表格部分: 该部分的html关键代码为: 其中整个表的标签为<tbody>标签,每行的标签为<tr>标签,每行中 ...
- csharp: DefaultValueAttribute Class
public class CalendarEvent { public int id { get; set; } public string title { get; set; } public st ...
- python基础之数据的三大结构
python的三大数据结构 1.顺序 2.分支 3.循环 # if语句联系# 如果age小于18岁,则打印信息“未成年”age = 17if age <= 18: print("未成年 ...
- 前端开发面试题-HTML(转载)
本文由 本文的原作者markyun 收集总结了一些前端面试题,初学者阅后也要用心钻研其中的原理,重要知识需要系统学习.透彻学习,形成自己的知识链.万不可投机取巧,临时抱佛脚只求面试侥幸混过关是错误的! ...
- js 乘除法小数问题
因为经常需要js来处理显示,就做下笔记 除法: function accDiv(arg1, arg2) { var t1 = 0, t2 = 0, r1, r2; try { t1 = arg1.to ...