[email protected] 发表于 2015-7-21 23:19:49

红外控制舵机

本帖最后由 [email protected] 于 2015-7-21 23:22 编辑

使用IRremote红外库控制舵机的角度,目前可以通过+-调整10度,0-9对应0-180度
#include <IRremote.h>
#include <Servo.h>

int RECV_PIN = 11;
int pos = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;
Servo myservo;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
myservo.attach(9);
}

void loop() {
if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    if (results.value == 0xA3C8EDDB) {//+
      pos += 10;
      if (pos >= 180) {
      pos = 180;
      }
    }
    if (results.value == 0xF076C13B) {//-
      pos -= 10;
      if (pos <= 0) {
      pos = 0;
      }
    }

    if (results.value == 0xC101E57B) {//0
      pos = 0;
    }

    if (results.value == 0x9716BE3F) {//1
      pos = 20;
    }

    if (results.value == 0x3D9AE3F7) {//2
      pos = 40;
    }

    if (results.value == 0x6182021B) {//3
      pos= 60;
    }

    if (results.value == 0x8C22657B) {//4
      pos= 80;
    }
    if (results.value == 0x488F3CBB) {//5
      pos = 100;
    }
    if (results.value == 0x449E79F) {//6
      pos = 120;
    }
    if (results.value == 0x32C6FDF7) {//7
      pos = 140;
    }
    if (results.value == 0x1BC0157B) {//8
      pos = 160;
    }
    if (results.value == 0x3EC3FC1B) {//9
      pos = 180;
    }
    myservo.write(pos);
}
delay(100);
}
http://v.youku.com/v_show/id_XMTI5MDMyNjI1Mg==.html
不会画图,大家都用什么软件画图的?
另外家里的屌丝空调遥控器每次按下同一个键反会的数据不一样,这是什么情况,怎么获取正确的值?大家碰到过没有?

zoologist 发表于 2015-7-22 09:57:43

推荐 tiny cad 效果还可以

艾弗森闯天涯 发表于 2015-9-1 23:22:13

LZ你好,我近期在做蓝牙小车,想用舵机控制小车的方向,可是我思考不出来一个办法用无线操作方法控制舵机,我就想比如我这边给一个指令,或者一直按着某个按键,舵机就正转或者反转,我松开,他就停止!还有能不能请求楼主把你这个实验具体用到的东西做个介绍或者列个清单我也想试试!:):):):P:P求楼主解惑答疑!谢谢了!
页: [1]
查看完整版本: 红外控制舵机