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
钟声敲响了日落
原文地址:https://www.cnblogs.com/SATinnovation/p/7818567.html