2987| 1
|
[求助] 红外遥控不成功 |
我复制了教程里面红外遥控灯的程序,可是上传后灯就一直亮着,重启也没用,打开串口监视器就不停地出0,0,0,0,0,0 怎么办,是判断部分代码有问题吗? 之前没有加判断部分前运行良好,监视器可以正常接收,加完判断和执行部分就不行了,为啥? 在线等大神帮助,谢谢! for(iled=1;iled<=8;iled+=1); { if(iled == 1); { analogWrite(LED1,1); analogWrite(LED2,1); delay(t); } // if(iled == 2); { analogWrite(LED1,4); analogWrite(LED2,4); delay(t); } // if(iled == 3); { analogWrite(LED1,13); analogWrite(LED2,13); delay(t); } // if(iled == 4); { analogWrite(LED1,32); analogWrite(LED2,32); delay(t); } // if(iled == 5); { analogWrite(LED1,62); analogWrite(LED2,62); delay(t); } // if(iled == 6); { analogWrite(LED1,108); analogWrite(LED2,108); delay(t); } // if(iled == 7); { analogWrite(LED1,171); analogWrite(LED2,171); delay(t); } // if(iled == 8); { analogWrite(LED1,255); analogWrite(LED2,255); delay(t); } } |
#include <IRremote.h> int RECV_PIN = 11; int ledPin = 10; // LED – digital 10 boolean ledState = LOW; // ledstate用来存储LED的状态 IRrecv irrecv(RECV_PIN); decode_results results; void setup(){ Serial.begin(9600); irrecv.enableIRIn(); pinMode(ledPin,OUTPUT); // 设置LED为输出状态 } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); //一旦接收到电源键的代码, LED翻转状态,HIGH变LOW,或者LOW变HIGH if(results.value == 0xFD00FF){ ledState = !ledState; //取反 digitalWrite(ledPin,ledState); //改变LED相应状态 } irrecv.resume(); } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed