我的 arduino 程序仅在启动时或按下重置按钮时运行,我不知道问题所在,因为我是这方面的新手。请需要帮助。
我这里有一些用于遥控器的常量,我只是想复制我通过 arduino ir led 发送的内容,除了程序只运行一次之外,一切正常。
#include <IRremote.h> // use the library
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
#define PanasonicPower 0x100BCBD // Panasonic Power button
#define PanasonicZero 0x1009899 // Panasonic button
#define PanasonicOne 0x1000809 // Panasonic button
#define PanasonicTwo 0x1008889 // Panasonic button
#define PanasonicThree 0x1004849 // Panasonic button
#define PanasonicFour 0x100C8C9 // Panasonic button
#define PanasonicFive 0x1002829 // Panasonic button
#define PanasonicSix 0x100A8A9 // Panasonic button
#define PanasonicSeven 0x1006869 // Panasonic button
#define PanasonicEight 0x100E8E9 // Panasonic button
#define PanasonicNine 0x1001819 // Panasonic button
#define PMute 0x1004C4D
#define PCPlus 0x1002C2D
#define PCMinus 0x100ACAD
#define PVMinus 0x1008485
#define PVPlus 0x1000405
#define PRTune 0x100ECED
#define JVCPower 0xC5E8
int receiverpin = 15; // pin 1 of IR receiver to Arduino digital pin 15
IRsend irsend;
IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // start the IR receiver
// pinMode(7, OUTPUT);
for (int z = 11 ; z < 14 ; z++) // set up digital pins
{
pinMode(z, OUTPUT);
}
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
for (int z = 0 ; z < 2 ; z++) // ignore the repeated codes
{
irrecv.resume(); // receive the next value
}
}
}
void translateIR()
// takes action based on IR code received
// uses Sony IR codes
{
switch(results.value)
{
case PanasonicFour: pinOnTriple(1, 0, 0);
irsend.sendPanasonic(PanasonicAddress,PanasonicFour); // This should turn your TV on and off
break; // 2
case PanasonicTwo: pinOnTriple(0, 1, 0);
irsend.sendPanasonic(PanasonicAddress,PanasonicTwo);
break; // 3
case PanasonicFive: pinOnTriple(HIGH, LOW, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicFive);
break; // 5
case PanasonicSix: pinOnTriple(HIGH, HIGH, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicSix);
break; // 6
case PanasonicSeven: pinOnTriple(HIGH, HIGH, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicSeven);
break; // 7
case PanasonicZero: pinOnTriple(LOW, LOW, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicZero);
break; // 8
case PanasonicOne: pinOnTriple(LOW, LOW, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicOne);
break; // 9
case PanasonicThree: pinOnTriple(LOW, HIGH, HIGH);
irsend.sendPanasonic(PanasonicAddress,PanasonicThree);
break; // 10
case 0x100BCBD: pinOnTriple(LOW, LOW, LOW);
irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off
irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat
delay(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information
irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat
delay(50);
break;
case 0x1004C4D:
irsend.sendPanasonic(PanasonicAddress,PMute);
break; // 11
case 0x1002C2D:
irsend.sendPanasonic(PanasonicAddress,PCPlus);
break; // 11
case 0x100ACAD:
irsend.sendPanasonic(PanasonicAddress,PCMinus);
break; // 11
case 0x1008485:
irsend.sendPanasonic(PanasonicAddress,PVMinus);
break; // 11
case 0x1000405:
irsend.sendPanasonic(PanasonicAddress,PVPlus);
break; // 11
case 0x100ECED:
irsend.sendPanasonic(PanasonicAddress,PRTune);
break; // 11
}
}
void pinOnTriple(int pin, int pino, int pini) // turns on digital pins for 1 second
{
digitalWrite(11, pin);
digitalWrite(12, pino);
digitalWrite(13, pini);
delay(1000);
digitalWrite(11, 0);
digitalWrite(12, 0);
digitalWrite(13, 0);
}