Télécommande Infra-rouge par l’ordinateur

Télécommande Infra-rouge par l’ordinateur.

Fichier : telecommande_ordi.pde

/*
 * Télécommande Infra-rouge par l'ordinateur 
 * IDE : 0.23
 */
 
 /*
 Code Télécommande Hexapode : 

    Haut : 
    90
    Decoded SONY: 90 (12 bits)
    
    Bas : 
    890
    Decoded SONY: 890 (12 bits)
    
    Droit : 
    490
    Decoded SONY: 490 (12 bits)
    
    Gauche : 
    C90
    Decoded SONY: C90 (12 bits)
    
    Arret :
    A90
    Decoded SONY: A90 (12 bits)
    
    Touche 0 :
    910
    Decoded SONY: 910 (12 bits)
    
    Touche 1 :
    10
    Decoded SONY: 10 (12 bits)
    
    Touche 2 :
    810
    Decoded SONY: 810 (12 bits)
    
    Touche 3 : 
    410
    Decoded SONY: 410 (12 bits)

    Liens :
      http://stackoverflow.com/questions/5697047/convert-serial-read-into-a-useable-string-using-arduino
      http://www.dfrobot.com/wiki/index.php?title=Digital_IR_Transmitter_Module%28SKU:DFR0095%29
      http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
 */

#include <IRremote.h>

IRsend irsend;

char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character

int vitesse = 100;

void setup() {
  Serial.begin(9600);
}

char Comp(char* This) {
    while (Serial.available() > 0) // Don't read unless
                                   // there you know there is data
    {
        if(index < 19) // One less than the size of the array
        {
            inChar = Serial.read(); // Read a character
            inData[index] = inChar; // Store it
            index++; // Increment where to write next
            inData[index] = '\0'; // Null terminate the string
        }
    }

    if (strcmp(inData,This)  == 0) {
        for (int i=0;i<19;i++) {
            inData[i]=0;
        }
        index=0;
        return(0);
    }
    else {
        return(1);
    }
}

void loop() {
  /*
    if (Serial.read() != -1) {
    for (int i = 0; i < 100; i++) {
      irsend.sendSony(0x90, 12); 
      Serial.print("Avancer\n");
      delay(100);
      }
    }
*/

   if (Comp("Avancer") == 0 || Comp("a") == 0) {
        for (int i = 0; i < vitesse; i++) {
           Serial.print("Avancer\n");
           irsend.sendSony(0x90, 12);
           delay(100);
        }          
    }

   if (Comp("Reculer") == 0 || Comp("r") == 0) {
        for (int i = 0; i < vitesse; i++) {
           Serial.print("Reculer\n");
           irsend.sendSony(0x890, 12);
           delay(100);
        }          
    }

   if (Comp("Droite") == 0 || Comp("d") == 0) {     
        for (int i = 0; i < vitesse; i++) {
           Serial.print("Droite\n");
           irsend.sendSony(0x490, 12);
           delay(100);
        }          
    }

   if (Comp("Gauche") == 0 || Comp("g") == 0) {
        for (int i = 0; i < vitesse; i++) {
           Serial.print("Gauche\n");
           irsend.sendSony(0xC90, 12);
           delay(100);
        }          
    } 
}

Add a Comment