voila mon code;
//-- librairies utilisées pour le module Ethernet------------------
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
#include <Client.h>
//-- librairies utilisées pour la décodage des trames infrarouge-----------
#include <IRremote.h>
// — Déclaration tableau tabIR —
#define TVCOL 0//colone de la télévision dans le tableau tabIR
#define DVDCOL 1//colone du DVD dans le tableau tabIR
#define RECCOL 2//colone du récepteur dans le tableau tabIR
#define COMMANDEOPTION 6//la taille de la colone du tabIR;
// — Déclaration des variables globales pour le module Ethernet —
byte mac = { 0x90, 0xA2, 0xDA, 0x0D, 0xEE, 0xA4 }; //physical mac address
byte ip = { 192, 168, 2, 11 }; // ip in lan
byte gateway = { 192, 168, 2, 10 }; // internet access via router
byte subnet = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
decode_results tabIR[3][COMMANDEOPTION];//tableau des code IR (tabIR).
int commandeOptionIndex = 0;
int materielleIndex = 0;// materielle:TV,DVD,RECEPTEUR
// — Déclaration des pin —
int RECV_PIN = 11;
int BUTTON_PIN = 2;
int STATUS_PIN = 8;
// -----------------------
IRrecv irrecv(RECV_PIN);//Création d’un objet IRrecv
decode_results results;//stocke les résultats de détecteur IR
IRsend irsend;
//-------- Storage for the recorded code--------------
int codeType =-9; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state
// Stores the code for later playback
// Most of this code is just logging
//**************** FONCTION SETUP = Code d’initialisation *****
void setup()
{
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600); // Initialisation de la liaison série
irrecv.enableIRIn(); //// Re-enable receiver(Réactiver le récepteur)
Serial.println(“server code test 1.0”); // so I can keep track of what is loaded
pinMode(BUTTON_PIN, INPUT);
pinMode(STATUS_PIN, OUTPUT);
}
//-------- fon. tab--------------/
void storeCode(decode_results *results, decode_results tabIR[COMMANDEOPTION]) {
codeType = results->decode_type;
int count = results->rawlen;//!!!taille d resultat
int i = 0;
//-------------codeType:est la protocole IR-----------
if (codeType == NEC) {
Serial.print("Received NEC: ");
if (results->value == REPEAT) {
// Don’t record a NEC repeat value as that’s useless.
Serial.println(“repeat; ignoring1.”);
return;
}
}
else if (codeType == SONY) {
Serial.print("Received SONY: ");
}
else if (codeType == RC5) {
Serial.print("Received RC5: ");
}
else if (codeType == RC6) {
Serial.print("Received RC6: ");
}
else {
Serial.print(“Unexpected codeType “);
Serial.print(codeType, DEC);
Serial.println(””);
}
Serial.println(results->value, HEX);
//-----------enregistrement des codes dand tabIR--------------
tabIR[materielleIndex][commandeOptionIndex] = *results;
if (commandeOptionIndex<6){
commandeOptionIndex++;
}else{
commandeOptionIndex = 0;
if(materielleIndex < 3)
materielleIndex++;
}//----------------fin enregistrement ------------------
}
//--------------Affichage tabIR ----------------
void afficher(decode_results tabIR[3][COMMANDEOPTION]){
Serial.println(“Affichage du tableau des CODES OPTIONS:”);
int i = 0;
int j = 0;
for (i = 0; i<3 ; i++){
switch(i){
case 0 :
Serial.println(“Affichage du tableau des CODES OPTIONS TV:”);
break;
case 1:
Serial.println(“Affichage du tableau des CODES OPTIONS DVD:”);
break;
case 2:
Serial.println(“Affichage du tableau des CODES OPTIONS RECEPTEUR”);
break;
}
for (j = 0; j<COMMANDEOPTION ; j++){
results=tabIR*[j];*
}
//----------------fon. send code ------------------
void sendCode(int repeat){
-
if (codeType == NEC) {*
-
if (repeat) {*
-
irsend.sendNEC(REPEAT, codeLen);*
-
Serial.println(“Sent NEC repeat”);*
-
}*
-
else {*
-
irsend.sendNEC(codeValue, codeLen);*
-
Serial.print("Sent NEC ");*
-
Serial.println(codeValue, HEX);//codeValue est la code IR*
-
}*
-
}*
-
else if (codeType == SONY) {*
-
irsend.sendSony(codeValue, codeLen);*
-
Serial.print("Sent Sony ");*
-
Serial.println(codeValue, HEX);*
-
}*
-
else if (codeType == RC5 || codeType == RC6) {*
-
if (!repeat) {*
-
// Flip the toggle bit for a new button press*
-
toggle = 1 - toggle;*
-
}*
-
// Put the toggle bit into the code to send*
-
codeValue = codeValue & ~(1 << (codeLen - 1));*
-
codeValue = codeValue | (toggle << (codeLen - 1));*
-
if (codeType == RC5) {*
-
Serial.print("Sent RC5 ");*
-
Serial.println(codeValue, HEX);*
-
irsend.sendRC5(codeValue, codeLen);*
-
}*
-
else {*
-
irsend.sendRC6(codeValue, codeLen);*
-
Serial.print("Sent RC6 ");*
-
Serial.println(codeValue, HEX);*
-
}*
-
}*
}
//--------------fon affichage page HTML— + traitement du msg pr l’envoie --------------
void afficheHTML(){
-
//en passe à la 2ème processus: *
-
EthernetClient client = server.available();*
-
if (client) {*
-
while (client.connected()) {*
-
if (client.available()) {*
-
char c = client.read();*
-
//read char by char HTTP request*
-
if (readString.length() < 100) {*
-
//store characters to string*
-
readString += c;*
-
//Serial.print(c);*
-
}*
-
//if HTTP request has ended*
-
if (c == ‘\n’) {*
-
///////////////partie client*
-
Serial.println(readString); //print to serial monitor for debuging*
-
client.println(“HTTP/1.1 200 OK”); //send new page*
-
client.println(“Content-Type: text/html”);*
-
client.println();*
-
client.println("");*
-
client.println("");*
-
client.println("");*
-
client.println("");*
-
client.println("");*
-
client.println(“Home Automation”);*
-
client.println("");*
-
client.println("");*
-
client.println(“
Home Automation
”);*
-
client.println("
");*
-
client.println("*
");
-
client.println("<a href="/?00"">Turn On TV");*
-
client.println("<a href="/?01"">Turn Off TV");*
-
client.println("<a href="/?02"">volume up TV"); *
-
client.println("<a href="/?03"">volume dwon TV");*
-
client.println("");*
-
client.println("");*
-
delay(1);*
-
//stopping client*
-
client.stop();*
-
if(readString.indexOf("?03")>0)*
-
{*
-
results= tabIR[0][3];*
-
codeLen=results.bits;*
-
codeValue=results.value;*
-
sendCode(true); *
-
}*
-
//clearing string for next read*
-
readString="";*
-
}*
-
}*
-
}*
-
}*
-
}*
//*************** FONCTION LOOP = Boucle sans fin = coeur du programme *************
// la fonction loop() s’exécute sans fin en boucle aussi longtemps que l’Arduino est sous tension
void loop() {
if (buttonState) {
-
if (irrecv.decode(&results)) {*
-
digitalWrite(STATUS_PIN,HIGH );*
-
irrecv.resume();*
-
storeCode(&results, tabIR);*
-
afficher( tabIR);*
-
digitalWrite(STATUS_PIN,LOW );*
-
delay(50); // Wait a bit between retransmissions*
-
}*
-
}*
}
code projet.txt (9.19 KB)