zoukankan      html  css  js  c++  java
  • 自制遥控风扇

    自制风扇

    /**
     * 风扇
     **/
    #include <IRremote.h>
    
     //////////千水星电机驱动/////////////////////////////////////////
    int input1 = 5; // 定义uno的pin 5 向 input1 输出
    int input2 = 6; // 定义uno的pin 6 向 input2 输出
    int input3 = 9; // 定义uno的pin 9 向 input3 输出
    int input4 = 10; // 定义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 initIR() {
      irrecv.enableIRIn();
    }
    
    
    void setup() {
      Serial.begin (9600);
      //初始化各IO,模式为OUTPUT 输出模式
      pinMode(input1, OUTPUT);
      pinMode(input2, OUTPUT);
      pinMode(input3, OUTPUT);
      pinMode(input4, OUTPUT);
      //初始化红外接收
      initIR();
    }
    
    void loop() {
      if (irrecv.decode(&results)) //如果接收到有红外发射器发送过来的数据
      {
        Serial.println(results.value, HEX);//以16进制换行输出接收代码
    
        if (results.value == 4294967295) {//红外长按得时候获取固定值
    
        } else {
          if (results.value == control[0][0]) {
    
          } else if (results.value == control[0][1]) {//
    
          } else if (results.value == control[0][2]) {
    
          } else if (results.value == control[1][0]) {//
    
          } else if (results.value == control[1][1]) {//
    
          } else if (results.value == control[1][2]) {//
    
          } else if (results.value == control[2][0]) {
    
          } else if (results.value == control[2][1]) {//
    
          } else if (results.value == control[2][2]) {
    
          } else if (results.value == control[3][0]) {//0
    
          } else if (results.value == control[3][1]) {
    
          } else if (results.value == control[3][2]) {//st
    
          } else if (results.value == control[4][0]) {//1
    
          } else if (results.value == control[4][1]) {//2
    
          } else if (results.value == control[4][2]) {//3
    
          } else if (results.value == control[5][0]) {//4
    
          } else if (results.value == control[5][1]) {//5
    
          } else if (results.value == control[5][2]) {//6
    
          } else if (results.value == control[6][0]) {//7
            //forward 向前转
            digitalWrite(input1, HIGH); //给高电平
            digitalWrite(input2, LOW); //给低电平
            digitalWrite(input3, HIGH); //给高电平
            digitalWrite(input4, LOW); //给低电平
            delay(1000);   //延时1秒
          } else if (results.value == control[6][1]) {//8
            //stop 停止
            digitalWrite(input1, LOW);
            digitalWrite(input2, LOW);
            digitalWrite(input3, LOW);
            digitalWrite(input4, LOW);
            delay(1000);  //延时0.5秒
          } else if (results.value == control[6][2]) {//9
            //back 向后转
            digitalWrite(input1, LOW);
            digitalWrite(input2, HIGH);
            digitalWrite(input3, LOW);
            digitalWrite(input4, HIGH);
            delay(1000);
          }
        }
        irrecv.resume(); // 接收下一个值
      }
      delay(100);
    
    }

     

  • 相关阅读:
    request.getParameter() 、 request.getInputStream()和request.getReader() 使用体会
    HTTP之Content-Length
    关于spring3中No Session found for current thread!and Transaction的配置和管理(转)
    Java数据类型和MySql数据类型对应一览
    Spring MVC 解读——View,ViewResolver(转)
    LeetCode 441. Arranging Coins
    LeetCode 415. Add Strings
    LeetCode 400. Nth Digit
    LeetCode 367. Valid Perfect Square
    LeetCode 326. Power of Three
  • 原文地址:https://www.cnblogs.com/SATinnovation/p/8157894.html
Copyright © 2011-2022 走看看