Moderators: adafruit_support_bill, adafruit
the program I have is written to display what key is pressed but it only works for the first 6 buttons
void setup(void) {
Serial.begin(9600);
Serial.println("Ready to decode IR!");
}
void loop(void) {
int numberpulses;
numberpulses = listenForIR();
Serial.print("Heard ");
Serial.print(numberpulses);
Serial.println("-pulse long IR signal");
if (IRcompare(numberpulses, CarMP3PREV,sizeof(CarMP3PREV)/4)) {
Serial.println("PREV");
}
if (IRcompare(numberpulses, CarMP3NEXT,sizeof(CarMP3NEXT)/4)) {
Serial.println("NEXT");
}
if (IRcompare(numberpulses, CarMP3PLAYPAUSE,sizeof(CarMP3PLAYPAUSE)/4)) {
Serial.println("PLAY/PAUSE");
}
if (IRcompare(numberpulses, CarMP3VOLmin,sizeof(CarMP3VOLmin)/4)) {
Serial.println("VOLmin");
}
if (IRcompare(numberpulses, CarMP3VOLplus,sizeof(CarMP3VOLplus)/4)) {
Serial.println("VOLplus");
}
if (IRcompare(numberpulses, CarMP3BEGIN,sizeof(CarMP3BEGIN)/4)) {
Serial.println("BEGIN"); //[b] ** NOTE: this is as far as it will work,[/b]
}
if (IRcompare(numberpulses, CarMP3MINUS,sizeof(CarMP3MINUS)/4)) {
Serial.println("MINUS");
}
if (IRcompare(numberpulses, CarMP3PLUS,sizeof(CarMP3PLUS)/4)) {
Serial.println("PLUS");
}Serial.println(F("-pulse long IR signal"));
Inserted the code mentioned but didn't seem to change anything....the compiler gives me this info...Binary sketch size: 7,622 bytes (of a 32,256 byte maximum) to I think we have room.
/* Raw IR Car commander
This sketch/program uses the Arduno and a PNA4602 to
decode IR received. It then attempts to match it to a previously
recorded IR signal
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/
// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
// uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2
// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000
#define NUMPULSES 50
// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20
// What percent we will allow in variation to match the same code
#define FUZZINESS 20
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[NUMPULSES][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
#include "carmp3codes.h"
void setup(void) {
Serial.begin(9600);
Serial.println(F("Ready to decode IR!"));
}
void loop(void) {
int numberpulses;
numberpulses = listenForIR();
Serial.print("Heard ");
Serial.print(numberpulses);
Serial.println(F("-pulse long IR signal"));
if (IRcompare(numberpulses, CarMP3PREV,sizeof(CarMP3PREV)/4)) {
Serial.println(F("PREV"));
}
else if (IRcompare(numberpulses, CarMP3NEXT,sizeof(CarMP3NEXT)/4)) {
Serial.println(F("NEXT"));
}
else if (IRcompare(numberpulses, CarMP3PLAYPAUSE,sizeof(CarMP3PLAYPAUSE)/4)) {
Serial.println(F("PLAY/PAUSE"));
}
else if (IRcompare(numberpulses, CarMP3VOLmin,sizeof(CarMP3VOLmin)/4)) {
Serial.println(F("VOLmin"));
}
else if (IRcompare(numberpulses, CarMP3VOLplus,sizeof(CarMP3VOLplus)/4)) {
Serial.println(F("VOLplus"));
}
else if (IRcompare(numberpulses, CarMP3BEGIN,sizeof(CarMP3BEGIN)/4)) {
Serial.println(F("BEGIN"));
}
else if (IRcompare(numberpulses, CarMP3MINUS,sizeof(CarMP3MINUS)/4)) {
Serial.println(F("MINUS"));
}
else if (IRcompare(numberpulses, CarMP3PLUS,sizeof(CarMP3PLUS)/4)) {
Serial.println(F("PLUS"));
}
else if (IRcompare(numberpulses, CarMP3EQ,sizeof(CarMP3EQ)/4)) {
Serial.println(F("EQ"));
}
else if (IRcompare(numberpulses, CarMP3ZERO,sizeof(CarMP3ZERO)/4)) {
Serial.println(F("ZERO"));
}
else if (IRcompare(numberpulses, CarMP3100plus,sizeof(CarMP3100plus)/4)) {
Serial.println(F("100plus"));
}
else if (IRcompare(numberpulses, CarMP3200plus,sizeof(CarMP3200plus)/4)) {
Serial.println(F("200plus"));
}
else if (IRcompare(numberpulses, CarMP3ONE,sizeof(CarMP3ONE)/4)) {
Serial.println(F("ONE"));
}
else if (IRcompare(numberpulses, CarMP3TWO,sizeof(CarMP3TWO)/4)) {
Serial.println(F("TWO"));
}
else if (IRcompare(numberpulses, CarMP3THREE,sizeof(CarMP3THREE)/4)) {
Serial.println(F("THREE"));
}
else if (IRcompare(numberpulses, CarMP3FOUR,sizeof(CarMP3FOUR)/4)) {
Serial.println(F("FOUR"));
}
else if (IRcompare(numberpulses, CarMP3FIVE,sizeof(CarMP3FIVE)/4)) {
Serial.println(F("FIVE"));
}
else if (IRcompare(numberpulses, CarMP3SIX,sizeof(CarMP3SIX)/4)) {
Serial.println(F("SIX"));
}
else if (IRcompare(numberpulses, CarMP3SEVEN,sizeof(CarMP3SEVEN)/4)) {
Serial.println(F("SEVEN"));
}
else if (IRcompare(numberpulses, CarMP3EIGHT,sizeof(CarMP3EIGHT)/4)) {
Serial.println(F("EIGHT"));
}
else if (IRcompare(numberpulses, CarMP3NINE,sizeof(CarMP3NINE)/4)) {
Serial.println(F("NINE"));
}
delay(500);
}
/******************* Car MP3 codes ************/
int CarMP3PREV[] = {
// ON, OFF (in 10's of microseconds)
878, 436,
56, 54,
58, 52,
50, 56,
56, 54,
58, 52,
52, 56,
56, 54,
58, 52,
50, 166,
60, 158,
56, 164,
52, 166,
58, 160,
56, 164,
52, 166,
58, 160,
56, 164,
52, 56,
56, 164,
50, 58,
56, 52,
58, 52,
52, 166,
56, 54,
52, 56,
54, 166,
50, 58,
52, 168,
50, 166,
56, 162,
56, 54,
56, 162,
54, 3890,
874, 222,
54, 0};
int CarMP3NEXT[] = {
882, 432,
60, 50,
56, 54,
56, 52,
58, 52,
54, 54,
58, 50,
60, 50,
58, 52,
56, 162,
56, 162,
58, 162,
54, 164,
56, 162,
58, 162,
52, 166,
56, 160,
60, 50,
56, 162,
60, 160,
54, 54,
58, 52,
58, 52,
56, 162,
54, 54,
54, 164,
56, 54,
54, 54,
58, 162,
52, 166,
54, 164,
58, 50,
56, 162,
60, 3884,
882, 214,
58, 2808,
882, 214,
56, 2812,
880, 214,
56, 0};
int CarMP3PLAYPAUSE[] = {
880, 434,
60, 50,
56, 54,
56, 52,
58, 52,
54, 56,
56, 50,
60, 50,
56, 54,
56, 162,
56, 162,
58, 162,
56, 162,
54, 164,
58, 162,
56, 160,
56, 162,
60, 160,
56, 162,
56, 162,
60, 50,
56, 54,
54, 54,
58, 162,
50, 58,
58, 50,
56, 54,
54, 54,
58, 162,
54, 164,
56, 162,
58, 52,
54, 164,
58, 3884,
882, 214,
58, 2808,
882, 214,
58, 2808,
882, 214,
58, 2808,
882, 214,
56, 0};
int CarMP3NINE[] = {
880, 434,
58, 50,
56, 54,
58, 50,
60, 50,
58, 52,
56, 52,
58, 52,
56, 54,
56, 160,
56, 162,
60, 160,
58, 160,
56, 162,
60, 160,
56, 162,
56, 162,
60, 50,
56, 162,
58, 50,
56, 162,
60, 50,
56, 54,
56, 162,
58, 52,
56, 162,
56, 54,
56, 162,
56, 54,
56, 160,
56, 162,
60, 50,
56, 162,
60, 3884,
880, 216,
56, 2810,
880, 216,
58, 2808,
880, 216,
60, 0};
boolean IRcompare(int numpulses, int Signal[], int refsize) {
int count = min(numpulses,refsize);
Serial.print("count set to: ");
Serial.println(count);
for (int i=0; i< count-1; i++)
{
int oncode = pulses[i][1] * RESOLUTION / 10;
int offcode = pulses[i+1][0] * RESOLUTION / 10;
#ifdef DEBUG
Serial.print(oncode); // the ON signal we heard
Serial.print(" - ");
Serial.print(pgm_read_word_near(Signal[i*2 + 0])_; // the ON signal we want
#endif
// check to make sure the error is less than FUZZINESS percent
if ( abs(oncode - pgm_read_word_near(Signal[i*2 + 0])+ <= pgm_read_word_near((Signal[i*2 + 0] * FUZZINESS / 100)))
{
#ifdef DEBUG
Serial.print(" (ok)");
#endif
}
else
{
#ifdef DEBUG
Serial.print(" (x)");
#endif
// we didn't match perfectly, return a false match
return false;
}
#ifdef DEBUG
Serial.print(" \t"); // tab
Serial.print(offcode); // the OFF signal we heard
Serial.print(" - ");
Serial.print(Signal[i*2 + 1]); // the OFF signal we want
#endif
if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100))
{
#ifdef DEBUG
Serial.print(" (ok)");
#endif}
else
{
#ifdef DEBUG
Serial.print(" (x)");
#endif
// we didn't match perfectly, return a false match
return false;
}
#ifdef DEBUG
Serial.println();
#endif
}
// Everything matched!
return true;
}Users browsing this forum: No registered users and 6 guests