zoukankan      html  css  js  c++  java
  • 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
         B-flash the lamp B
         C-flash the lamp C
         D-flash the lamp D
    ");
      Serial.print("     a-open the lamp A
         b-open  the lamp B
         c-open the lamp C
         d-open  the lamp D
    
    ");
        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
    ");
     mySwitch.send("010101010101010100001100");//遥控器-A
      Serial.print("      OK!!! The LED A has been DONE
    ");
        }
           if(M=='a')
        {
         Serial.print("The command is a
    ");
         Serial.print("      OK!!! TheLED A has hlod ON
    ");
         while(Serial.available()<=0)
          {
          mySwitch.send("010101010101010100001100");//遥控器-A 按下不放
          }
        }
      if(M=='B')
        {
      Serial.print("Thecommand is B
    ");
     mySwitch.send("010101010101010111000000");//遥控器-B
      Serial.print("      OK!!! The LED B has been DONE
    ");
        }
         if(M=='b')
        {
         Serial.print("The command is b
    ");
          Serial.print("      OK!!! The LED B has hlod ON
    ");
         while(Serial.available()<=0)
          {
          mySwitch.send("010101010101010111000000");//遥控器-B 按下不放
          }
        }
      if(M=='C')
        {
      Serial.print("Thecommand is C
    ");
     mySwitch.send("010101010101010100000011");//遥控器-C
      Serial.print("      OK!!! The LED C has been DONE
    ");
        }
             if(M=='c')
        {
         Serial.print("The command is c
    ");
         Serial.print("      OK!!! TheLED C has hlod ON
    ");
         while(Serial.available()<=0)
          {
          mySwitch.send("010101010101010100000011");//遥控器-C按下不放
          }
        }
      if(M=='D')
        {
      Serial.print("Thecommand is D
    ");
     mySwitch.send("010101010101010100110000");//遥控器-D
      Serial.print("      OK!!! The LED D has been DONE
    ");
        }
             if(M=='d')
        {
         Serial.print("The command is d
    ");
         Serial.print("      OK!!! TheLED D has hlod ON
    ");
         while(Serial.available()<=0)
          {
          mySwitch.send("010101010101010100110000");//遥控器-D按下不放
          }
        }
      }
    }
    

      

  • 相关阅读:
    js数组与字符串的相互转换方法
    js页面跳转常用的几种方式
    js刷新页面方法大全
    IIS上开启反向代理实现Vue项目接口跨域处理
    【问题解决记录】vue解决低版本安卓与ios10以下系统兼容性问题
    【解决问题记录】https网站中请求http资源接口报错与netERRSSLPROTOCOLERROR错误的解决
    indexedDb数据库基本操作
    Object常用方法
    htmlToTex
    禁止鼠标右键保存/拖动/选中/复制 图片/文字
  • 原文地址:https://www.cnblogs.com/kekeoutlook/p/8213903.html
Copyright © 2011-2022 走看看