zoukankan      html  css  js  c++  java
  • cq

    /*
     *遥控程序
     */
    
    #include <IRremote.h>     // IRremote库声明  
    
    int input1 = 9; // 定义uno的pin 5 向 input1 输出   
    int input2 = 10; // 定义uno的pin 6 向 input2 输出  
    int input3 = 5; // 定义uno的pin 9 向 input3 输出  
    int input4 = 6; // 定义uno的pin 10 向 input4 输出  
    
    int RECV_PIN = 3;
    IRrecv irrecv(RECV_PIN);
    decode_results results;
    
    long control[7][3] = {//遥控器矫正数字
      {16580863, 16613503, 16597183},
      {16589023, 16621663, 16605343},
      {16584943, 16617583, 16601263},
      {16593103, 16625743, 16609423},
      {16582903, 16615543, 16599223},
      {16591063, 16623703, 16607383},
      {16586983, 16619623, 16603303}
    };
    
    void initRun(){// init
      pinMode(input1,OUTPUT);  
      pinMode(input2,OUTPUT);  
      pinMode(input3,OUTPUT);  
      pinMode(input4,OUTPUT); 
    }
    
    void setup()
    {
      Serial.begin(9600);
      irrecv.enableIRIn(); // 启动接收器
      initRun();
    }
    
    void left(){
      digitalWrite(input1,HIGH); //给高电平  
      digitalWrite(input2,LOW);  //给低电平  
      delay(1000);   //延时1秒  
    }
    void right(){
      digitalWrite(input1,LOW);  
      digitalWrite(input2,HIGH);       
      delay(1000); 
    }
    void goRun(){
      digitalWrite(input3,HIGH); //给高电平  
      digitalWrite(input4,LOW);  //给低电平  
      delay(1000);   //延时1秒  
    }
    void goBack(){
      digitalWrite(input3,LOW);  
      digitalWrite(input4,HIGH);    
      delay(1000);    
    }
    void goStop(){
      //stop 停止  
     digitalWrite(input1,LOW);  
     digitalWrite(input2,LOW);    
     digitalWrite(input3,LOW);  
     digitalWrite(input4,LOW);    
     delay(1000);  //延时0.5秒  
    }
    
    void loop() {
      if (irrecv.decode(&results))
      {
        Serial.println(results.value, HEX);//以16进制换行输出接收代码
        if (results.value == 4294967295) {
          //long click
          
        } else {
          if (results.value == control[0][0]) {
            
          } else if (results.value == control[0][1]) {//
            goRun();
          } else if (results.value == control[0][2]) {
            
          } else if (results.value == control[1][0]) {//
            left();
          } else if (results.value == control[1][1]) {//
            goStop();
          } else if (results.value == control[1][2]) {//
            right();
          } else if (results.value == control[2][0]) {
            
          } else if (results.value == control[2][1]) {//
            goBack();
          } else if (results.value == control[2][2]) {
            
          } else if (results.value == control[3][0]) {
            
          } else if (results.value == control[3][1]) {
            
          } else if (results.value == control[3][2]) {
            
          } else if (results.value == control[4][0]) {
            
          } else if (results.value == control[4][1]) {
            
            
          } else if (results.value == control[4][2]) {
            
            
          } else if (results.value == control[5][0]) {
            
            
          } else if (results.value == control[5][1]) {
            
            
          } else if (results.value == control[5][2]) {
            
            
          } else if (results.value == control[6][0]) {
            
            
          } else if (results.value == control[6][1]) {
            
            
          } else if (results.value == control[6][2]) {
            
            
          }
        }
        irrecv.resume(); // 接收下一个值
      }
      delay(100);
    }
    View Code
    钟声敲响了日落
  • 相关阅读:
    预搜索,不匹配;反向预搜索,不匹配
    反向引用 /1, /2...
    贪婪与非贪婪模式
    其他一些代表抽象意义的特殊符号
    修饰匹配次数的特殊符号
    自定义能够匹配 ' 多种字符' 的表达式
    能够与 ' 多种字符' 匹配的表达式
    6)添加带有颜色的那个画板
    5)添加快捷键
    4)记住我的图形
  • 原文地址:https://www.cnblogs.com/SATinnovation/p/7818567.html
Copyright © 2011-2022 走看看