my arduino program runs when on start or when press reset button, dont know problem new bee this. please need help.
i have constants here remote control, , trying replicate sending through arduino ir led, every thing works fine except program runs once.
#include <irremote.h> // use 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 arduino digital pin 15 irsend irsend; irrecv irrecv(receiverpin); // create instance of irrecv decode_results results; void setup() { serial.begin(9600); irrecv.enableirin(); // start ir receiver // pinmode(7, output); (int z = 11 ; z < 14 ; z++) // set digital pins { pinmode(z, output); } } void loop() { if (irrecv.decode(&results)) // have received ir signal? { translateir(); (int z = 0 ; z < 2 ; z++) // ignore repeated codes { irrecv.resume(); // receive 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); // should turn tv on , 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); // should turn tv on , off irsend.sendjvc(jvcpower, 16,0); // hex value, 16 bits, no repeat delay(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php 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 1 second { digitalwrite(11, pin); digitalwrite(12, pino); digitalwrite(13, pini); delay(1000); digitalwrite(11, 0); digitalwrite(12, 0); digitalwrite(13, 0); }
you should check receiving repeat codes (0xffffff) , ignore code. , issue resume command once. may accidently skipping valid codes.
also, need issue resume after transmitting ir (as tx disables rx).
this last 1 issue you.
hope helps
may worth putting in delay before re-tx tx may overlap repeat codes
for interested in ir protocols - have launched project analysir - ir decoder & analyzer gui (arduino & raspberry pi). support 17 ir protocols , looking more add part of campaign. suggestions welcome!
if project successful, hope add support raspberry pi !
you can find out more , support project visiting http://igg.me/at/analysir/x/3752156 or screenshot via www.analysir.com
Comments
Post a Comment