Modifications

Sauter à la navigation Sauter à la recherche
139 octets ajoutés ,  4 avril 2019 à 16:38
aucun résumé de modification
Ligne 10 : Ligne 10 :     
  <nowiki>
 
  <nowiki>
    void printpulses(void) {
+
void printpulses(void) {
 
     Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
 
     Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
 
     for (uint8_t i = 0; i < currentpulse; i++) {
 
     for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
+
      Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
+
      Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
+
      Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
+
      Serial.println(" usec");
 
     }
 
     }
 
     // print it in a 'array' format
 
     // print it in a 'array' format
Ligne 22 : Ligne 22 :  
     Serial.println("// ON, OFF (in 10's of microseconds)");
 
     Serial.println("// ON, OFF (in 10's of microseconds)");
 
     for (uint8_t i = 0; i < currentpulse-1; i++) {
 
     for (uint8_t i = 0; i < currentpulse-1; i++) {
    Serial.print("\t"); // tab
+
      Serial.print("\t"); // tab
    Serial.print(pulses[i][1] * RESOLUTION / 10, DEC);
+
      Serial.print(pulses[i][1] * RESOLUTION / 10, DEC);
    Serial.print(", ");
+
      Serial.print(", ");
    Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
+
      Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
    Serial.println(",");
+
      Serial.println(",");
 
     }
 
     }
 
     Serial.print("\t"); // tab
 
     Serial.print("\t"); // tab
 
     Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
 
     Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
 
     Serial.print(", 0};");
 
     Serial.print(", 0};");
    }
+
}
 
</nowiki>
 
</nowiki>
   −
I uploaded the new sketch and pressed the Play button on the Apple remote and got the following:
+
Le nouveau croquis téléversé sur notre Arduino, pressons le bouton "Jouer" de la télécommande et voyons le résutlat que nous allons obtenir:
    
  <nowiki>
 
  <nowiki>
 
+
int IRsignal[] = { // ON, OFF (in 10's of microseconds)
 
  −
    int IRsignal[] = { // ON, OFF (in 10's of microseconds)
   
     912, 438,
 
     912, 438,
 
     68, 48,
 
     68, 48,
Ligne 77 : Ligne 75 :  
     66, 3012,
 
     66, 3012,
 
     908, 212,
 
     908, 212,
     68, 0};
+
     68, 0 };
 
</nowiki>
 
</nowiki>
   −
We'll try to detect that code. Lets start a new sketch called IR Commander ([http://github.com/adafruit/IR-Commander la version finale du code est disponible sur le GitHub d'AdaFruit]) this will use parts of our previous sketch. The first part we'll do is to create a function that just listens for an IR code an puts the pulse timings into the pulses[] array. It will return the number of pulses it heard as a return-value.
+
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.
    
  <nowiki>
 
  <nowiki>
    int listenForIR(void) {
+
int listenForIR(void) {
    currentpulse = 0;
+
currentpulse = 0;
    while (1) {
+
while (1) {
 
     uint16_t highpulse, lowpulse; // temporary storage timing
 
     uint16_t highpulse, lowpulse; // temporary storage timing
 
     highpulse = lowpulse = 0; // start out with no pulse length
 
     highpulse = lowpulse = 0; // start out with no pulse length
 
     // while (digitalRead(IRpin)) { // this is too slow!
 
     // while (digitalRead(IRpin)) { // this is too slow!
 
     while (IRpin_PIN & (1 << IRpin)) {
 
     while (IRpin_PIN & (1 << IRpin)) {
    // pin is still HIGH
+
      // pin is still HIGH
    // count off another few microseconds
+
      // count off another few microseconds
    highpulse++;
+
      highpulse++;
    delayMicroseconds(RESOLUTION);
+
      delayMicroseconds(RESOLUTION);
    // If the pulse is too long, we 'timed out' - either nothing
+
      // If the pulse is too long, we 'timed out' - either nothing
    // was received or the code is finished, so print what
+
      // was received or the code is finished, so print what
    // we've grabbed so far, and then reset
+
      // we've grabbed so far, and then reset
    if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
+
      if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
    return currentpulse;
+
          return currentpulse;
    }
+
      }
 
     }
 
     }
 
     // we didn't time out so lets stash the reading
 
     // we didn't time out so lets stash the reading
Ligne 105 : Ligne 105 :  
     // same as above
 
     // same as above
 
     while (! (IRpin_PIN & _BV(IRpin))) {
 
     while (! (IRpin_PIN & _BV(IRpin))) {
    // pin is still LOW
+
      // pin is still LOW
    lowpulse++;
+
      lowpulse++;
    delayMicroseconds(RESOLUTION);
+
      delayMicroseconds(RESOLUTION);
    if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
+
      if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
    return currentpulse;
+
          return currentpulse;
    }
+
      }
 
     }
 
     }
 
     pulses[currentpulse][1] = lowpulse;
 
     pulses[currentpulse][1] = lowpulse;
Ligne 116 : Ligne 116 :  
     currentpulse++;
 
     currentpulse++;
 
     }
 
     }
    }
+
}
 
</nowiki>
 
</nowiki>
  
29 910

modifications

Menu de navigation