ich habe ein Programm geschrieben, welches IR Codes einer Fernbedienung einliest eund mit vorhandenen Codes vergleicht.

Die Funktion, welche die Codes vergleicht funktioniert auch einwandfrei, allerdings prüft diese immer nur den eingelesenen Code mit EINEM Code aus der Codeliste.

Nun habe ich durch einige else if () {} Verschachtelungen erst überprüft, ob der erste Code passt, dann der zweite usw. allerdings geht das nur bis zum 8. Code.
Denn wenn ich den 9. in die Abfrage eingliedere, startet der Arduino immer nur neu oder gibt viele unnütze Zeichen aus wenn ich eine Taste der Fernbedienung drücke.
(die Funktion funktioniert allerdings wenn ich min. 2 Abfragen aus der Funktion evaluate(); entferne)

Ich vermute mal, dass die Funktion die die Codes vergleicht zu komplex ist um in so vielen Abfragen genutzt zu werden, aber ich brauche dazu mal eine Lösung …

Programmcode und Serial Monitor siehe unten:

#define IRpin_PIN      PIND
#define IRpin          2
 
#define MAXPULSE 65000
#define NUMPULSES 50
#define RESOLUTION 20 
 
 
 
int debug = ;
int currentpulse = ;
float fuzziness = 20;
 
int pulses[NUMPULSES][2];
 
#include "ircodes.h"
 
void setup(void) {
  Serial.begin(9600);
  Serial.println("\nReady to decode IR!");
}
 
 
int listenForIR(void) {
 currentpulse = ;
 
  while (1) {
    unsigned long highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = ; // start out with no pulse length
 
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
       // pin is still HIGH
 
       // count off another few microseconds
       highpulse++;
       delayMicroseconds(RESOLUTION);
 
       // If the pulse is too long, we 'timed out' - either nothing
       // was received or the code is finished, so print what
       // we've grabbed so far, and then reset
 
       // KGO: Added check for end of receive buffer
       if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
         return currentpulse;
       }
    }
    // we didn't time out so lets stash the reading
    pulses[currentpulse][] = highpulse;
 
    // same as above
    while (! (IRpin_PIN & _BV(IRpin))) {
       // pin is still LOW
       lowpulse++;
       delayMicroseconds(RESOLUTION);
        // KGO: Added check for end of receive buffer
        if (((lowpulse >= MAXPULSE)  && (currentpulse != 0))|| currentpulse == NUMPULSES) {
         return currentpulse;
       }
    }
    pulses[currentpulse][1] = lowpulse;
 
    // we read one high-low pulse successfully, continue!
    currentpulse++;
  }
}
 
 
 
boolean compareIR(int stored[] )
        { int length = stored[];
          int solution = ;
          int error = 3;
 
 
          int offpulse[currentpulse];
          int onpulse[currentpulse];
 
          float upper =;
          float lower =;
 
          if(currentpulse != length)
            {solution = error+1;}
 
 
 
          for(int i=0 ; i< currentpulse-1 && solution <= error ; i++)
              {if(i==)
                 {onpulse[i]=currentpulse;
                  offpulse[i] =;
 
 
                 } 
               offpulse[i+1] = pulses[i+1][];
               onpulse[i+1]  = pulses[i][1];
 
 
               upper = stored[i*2]*(1+fuzziness/100);
               lower = stored[i*2]*(1-fuzziness/100);
 
 
 
               if(onpulse[i] <= upper && onpulse[i] >= lower)
                  { 
 
 
 
                      }
 
                  else{
                       solution ++; 
 
 
                       }
 
               upper = stored[i*2+1]*(1+fuzziness/100);
               lower = stored[i*2+1]*(1-fuzziness/100);
 
 
                     if(offpulse[i] <= upper && offpulse[i] >= lower )
                        {    
 
                        }
 
                        else{
                             solution++;
 
 
 
                             }  
 
 
 
               }
 
         if(solution <= error)
           {solution = 1;}
           else{solution = ;} 
 
        return solution;
         }
 
 
 
int evaluate (){
                  int button; 
 
                  if( compareIR(Mute) == 1)
                    { button =1;
                      Serial.println("Pressed: Mute");
                    }
                  else if( compareIR(Zwei) == 1)
                           { button =2;
                             Serial.println("Pressed: 2.1");
                           }    
                 else if( compareIR(Fuenf) == 1)
                                   { button =3;
                                     Serial.println("Pressed: 5.1");
                                   }
                 else if( compareIR(AC) == 1)
                                          { button =4;
                                            Serial.println("Pressed: AC-3");
                                          }
                 else if( compareIR(BPlus) == 1)
                                                 { button =5;
                                                   Serial.println("Pressed: Bass +");
                                                 } 
                 else if( compareIR(BMinus) == 1 )
                                                        { button =6;
                                                          Serial.println("Pressed: Bass -");
                                                        } 
              else  if( compareIR(TPlus) == 1)
                                                                 { button =7;
                                                                   Serial.println("Pressed: Treble +");
                                                                 }
                  else  if( compareIR(TMinus) == 1)
                                                                        { button =8;
                                                                          Serial.println("Pressed: Treble -");
                                                                        }
              else if( compareIR(VPlus) == 1)
                                                                               { button =9;
                                                                                 Serial.println("Pressed: Vol +");
                                                                               } 
                 else if( compareIR(VMinus) == 1)
                                                                                      { button =10;
                                                                                        Serial.println("Pressed: Vol -");
                                                                                      }                                                      
 
               else{Serial.println("no match");
                      button = ;}                                                    
 
 
                 return button;                                                                     
                }
 
 
 
 
void loop(void) {
  int numberpulses;
  int test = 11;
  int button;
 
  numberpulses = listenForIR();
 
  Serial.print("Heard ");
  Serial.print(numberpulses);
  Serial.println("-pulse long IR signal");
 
 test = evaluate();
 Serial.print("\nErgebnis -- > ");
 Serial.println(test);
 
}
Quote: