[ESP32-Audio-Kit音频开发板测评]IR红外遥控LED灯
<div class='showpostmsg'><p>在配件IR红外接收模块的情况下,开发板可进行LED灯遥控操作,其整体构成如图1所示。</p><p>图1 整体构成</p>
<p>红外接收模块所连接的引脚为D0,控制的LED为开发板上的LED4和LED5.</p>
<p>其相应的程序如下:</p>
<pre>
<code class="language-cpp">#include <IRremote.h>
int RECV_PIN = 5,f,p; //D0;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long v;
void setup()
{
pinMode(22, OUTPUT); // LED4
digitalWrite(22, HIGH);
pinMode(19, OUTPUT); // LED5
digitalWrite(19, HIGH);
Serial.begin(115200);
Serial.print("IR: ");
irrecv.enableIRIn();}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
v=results.value;
irrecv.resume();
if(v == 0xFFA25D)
{
Serial.println(v, DEC);
if(f==0) f=1;
else f=0;
v=0;
}
if(v == 0xFFE21D)
{
Serial.println(v, DEC);
if(f==0) p=1;
else p=0;
v=0;
}
if(f==1) digitalWrite(22, LOW); //on
else digitalWrite(22, HIGH); //off
if(p==1) digitalWrite(19, LOW); //on
else digitalWrite(19, HIGH); //off
}
}</code></pre>
<p>经编译和上传,其运行结果如图2和图3所示。</p>
<p>图2 串口监视器所显示的键值</p>
<p> </p>
<p>图3 遥控器打开LED</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>这种板子玩玩红外遥控还是容易一些的</p>
<p> </p>
页:
[1]