| Ligne 80 : |
Ligne 80 : |
| | Nous allons essayer de détecter ce code. Essayons de démarrer un nouveau croquis appelé IR Commander ([http://github.com/adafruit/IR-Commander la version finale du code est disponible sur le GitHub d'AdaFruit]) qui utilisera une partie de notre précédent croquis. | | Nous allons essayer de détecter ce code. Essayons de démarrer un nouveau croquis appelé IR Commander ([http://github.com/adafruit/IR-Commander la version finale du code est disponible sur le GitHub d'AdaFruit]) qui utilisera une partie de notre précédent croquis. |
| | | | |
| − | La première partie écourtera simplement le code Infrarouge et placera les temps d'impulsion dans le tableau pulses[]. Il retournera le nombre d'impulsions détecté comme valeur de retour. | + | La première partie écourtera simplement le code Infrarouge et placera les temps d'impulsion dans le tableau {{fname|pulses[]}}. Il retournera le nombre d'impulsions détecté comme valeur de retour. |
| | | | |
| | <nowiki> | | <nowiki> |
| Ligne 119 : |
Ligne 119 : |
| | </nowiki> | | </nowiki> |
| | | | |
| − | Our new '''loop()''' will start out just listening for pulses
| + | Notre nouvelle fonction {{fname|loop()}} ne fera qu' "écouter" après les impulsions. |
| | | | |
| | <nowiki> | | <nowiki> |
| − | void loop(void) {
| + | void loop(void) { |
| | int numberpulses; | | int numberpulses; |
| | numberpulses = listenForIR(); | | numberpulses = listenForIR(); |
| Ligne 128 : |
Ligne 128 : |
| | Serial.print(numberpulses); | | Serial.print(numberpulses); |
| | Serial.println("-pulse long IR signal"); | | Serial.println("-pulse long IR signal"); |
| − | }
| + | } |
| | </nowiki> | | </nowiki> |
| | | | |
| − | When we run this it will print out something like...
| + | Lorsqu'il fonctionne, il affiche quelque chose comme ceci... |
| | | | |
| | {{ADFImage|IR-pulsecounter.jpg}} | | {{ADFImage|IR-pulsecounter.jpg}} |
| | | | |
| − | OK time to make the sketch compare what we received to what we have in our stored array: | + | OK, il est maintenant temps de faire en sorte que notre croquis compare ce qu'il à reçu et ce qu'il a déjà dans le notre tableau de référence: |
| | | | |
| | {{ADFImage|IR-ircompare.jpg}} | | {{ADFImage|IR-ircompare.jpg}} |
| | | | |
| − | As you can see, there is some variation. So when we do our comparison we can't look for preciesely the same values, we have to be a little 'fuzzy'. We'll say that the values can vary by 20% - that should be good enough.
| + | Comme vous pouvez le voir, il y a quelques variations. Lorsque nous faisons la comparaison, nous ne pouvons malheureusement pas attendre d'avoir exactement les mêmes valeurs, nous devons opter pour une méthode un peu plus 'créative'. |
| | + | |
| | + | Disons que la valeur peu varier d'environ 20% - cela devrait être suffisant. |
| | | | |
| | <nowiki> | | <nowiki> |
| | + | // Quel pourcentage de variation est toléré durant la comparaison de deux code |
| | + | #define FUZZINESS 20 |
| | | | |
| − | | + | void loop(void) { |
| − | // What percent we will allow in variation to match the same code \\ #define FUZZINESS 20
| |
| − | void loop(void) {
| |
| | int numberpulses; | | int numberpulses; |
| | numberpulses = listenForIR(); | | numberpulses = listenForIR(); |
| Ligne 152 : |
Ligne 154 : |
| | Serial.println("-pulse long IR signal"); | | Serial.println("-pulse long IR signal"); |
| | for (int i=0; i< numberpulses-1; i++) { | | for (int i=0; i< numberpulses-1; i++) { |
| − | int oncode = pulses[i][1] * RESOLUTION / 10;
| + | int oncode = pulses[i][1] * RESOLUTION / 10; |
| − | int offcode = pulses[i+1][0] * RESOLUTION / 10;
| + | int offcode = pulses[i+1][0] * RESOLUTION / 10; |
| − | Serial.print(oncode); // the ON signal we heard
| + | |
| − | Serial.print(" - ");
| + | Serial.print(oncode); // le signal ON réceptionné |
| − | Serial.print(ApplePlaySignal[i*2 + 0]); // the ON signal we want
| + | Serial.print(" - "); |
| − | // check to make sure the error is less than FUZZINESS percent
| + | Serial.print(ApplePlaySignal[i*2 + 0]); // Le signal ON attendu |
| − | if ( abs(oncode - ApplePlaySignal[i*2 + 0]) <= (oncode * FUZZINESS / 100)) {
| + | // Vérifier pour s'arrure que l'erreur est inférieure à FUZZINESS pourcent |
| − | Serial.print(" (ok)");
| + | if ( abs(oncode - ApplePlaySignal[i*2 + 0]) <= (oncode * FUZZINESS / 100)) { |
| − | } else {
| + | Serial.print(" (ok)"); |
| − | Serial.print(" (x)");
| + | } else { |
| − | }
| + | Serial.print(" (x)"); |
| − | Serial.print(" \t"); // tab
| + | } |
| − | Serial.print(offcode); // the OFF signal we heard
| + | Serial.print(" \t"); // tab |
| − | Serial.print(" - ");
| + | |
| − | Serial.print(ApplePlaySignal[i*2 + 1]); // the OFF signal we want
| + | Serial.print(offcode); // Le signal OFF réceptionné |
| − | if ( abs(offcode - ApplePlaySignal[i*2 + 1]) <= (offcode * FUZZINESS / 100)) {
| + | Serial.print(" - "); |
| − | Serial.print(" (ok)");
| + | Serial.print(ApplePlaySignal[i*2 + 1]); // Le signal OFF attendu |
| − | } else {
| + | if ( abs(offcode - ApplePlaySignal[i*2 + 1]) <= (offcode * FUZZINESS / 100)) { |
| − | Serial.print(" (x)");
| + | Serial.print(" (ok)"); |
| − | }
| + | } else { |
| − | Serial.println();
| + | Serial.print(" (x)"); |
| − | }
| + | } |
| | + | Serial.println(); |
| | } | | } |
| | + | } |
| | </nowiki> | | </nowiki> |
| | | | |
| | {{ADFImage|IR-codecompareok.jpg}} | | {{ADFImage|IR-codecompareok.jpg}} |
| − |
| |
| − |
| |
| | | | |
| | This loop, as it goes through each pulse, does a little math. It compares the absolute ('''abs()''') difference between the code we heard and the code we're trying to match abs(oncode - ApplePlaySignal[i*2 + 0]) and then makes sure that the error is less than FUZZINESS percent of the code length (oncode * FUZZINESS / 100) | | This loop, as it goes through each pulse, does a little math. It compares the absolute ('''abs()''') difference between the code we heard and the code we're trying to match abs(oncode - ApplePlaySignal[i*2 + 0]) and then makes sure that the error is less than FUZZINESS percent of the code length (oncode * FUZZINESS / 100) |