IR et LCD

Photo Christian Carnet



Un projet pour manipuler un peut tout autour de l'IR (réception de la télécommande) et du shield LCD 16X2










// -----------------------------------------------
// Lecture telecommande et affichage sur ecran LCD
// Avec teleco Arduino ...
// Le bouton Marche / Arret lance le clignotement 
// d'une led 
// -----------------------------------------------

// include the library code:
#include <IRremote.h>
#include <LiquidCrystal.h>

// Constantes 
const int Infra = 40;
const int numRows = 2;      // 2 lignes 
const int numCols = 16;     // 16 colonnes
const int Led = 44;
const int temperature=8;    // Entrée analogique
const int touche=0;         // Touche du clavier LCD
const int tilt=24;          // Capteur de tilt

// Initialisation port Infrarouge 
IRrecv irrecv(Infra);
int valinfradec;

// Variables diverses
boolean valled=HIGH;
boolean bclignote;
int Mode;
float valtemp;
int valtouche;
int valtilt;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

// Stockage données infra rouge
decode_results results;

// -------------------
// Fonction SETUP
// -------------------
void setup()
{
  //Capteurs en sortie
  pinMode(Led, OUTPUT); 
  
  // capteurs en entrée
  pinMode(temperature, INPUT); 
  pinMode(touche, INPUT); 
  pinMode(tilt, INPUT);

  // Port serie
  Serial.begin(9600);
  
  // Affichage message d'accueil
  //lcd.begin(16,2);  // Initialisation LCD lignes / colonnes
  lcd.write("Test TELECO..."); 
  delay(1000);
  lcd.setCursor(0,1); lcd.write("Pret");
  
  // Capteur infra rouge
  irrecv.enableIRIn();         // Start the receiver
}

// -----------------
// BOUCLE PRINCIPALE
// -----------------
void loop() 
{
  // Traitement du capteur de tilt
  TraiteTilt();
  
  // Traitement des touches du panneau LCD
  TraiteTouche();
  
  // Traitement entrées télécommande
  TraiteTeleco();
  
  // Traitement temperature
  TraiteTemperature();
  
  // traitement clignotement
   if (bclignote==true) clignote();
}

// -------------------
// Traitement du Tilt
// -------------------
void TraiteTilt()
{
  valtilt=digitalRead(tilt);
  if (valtilt != 0)
  {
  Serial.println("TILT !!");
  }
}

// ------------------
// Traitement du mode 
// ------------------
void TraiteMode()
{
    Mode++;
       if (Mode>3)
       {
         Mode=1;
       } 
       
       lcd.setCursor(0,0); 
       switch (Mode)
       {
         case 1 :
         lcd.write("Mode SPORT      ");
         break;
         
         case 2 :
         lcd.write("Mode STANDARD   ");
         break;
         
         case 3 :
         lcd.write("Mode CONFORT    ");
         break;
       }
}

// ------------------------------------
// Fonction TraiteTouche (Shield Ecran)
// ------------------------------------
void TraiteTouche()
{
  valtouche=analogRead(touche);
  switch (valtouche) 
  {
    case 741:  // Select
    break;
    case 505:  // Left
    break;
    case 142:  // Up
      TraiteMode();
    break;
    case 331:  // Down
    break;
    case 0:    // Right
    break;
  }
}

// --------------------
// Fonction temperature
// --------------------
void TraiteTemperature()
{
  valtemp=analogRead(temperature);
 
  valtemp=valtemp * 5.0 / 1024.0;
  valtemp=valtemp * 100;
  //Serial.println(valtemp);
  //lcd.setCursor(1,1); lcd.write("34");
}

// ---------------------
// Fonction clignotement 
// ---------------------
void clignote()
{
  valled=!valled;
  digitalWrite(Led,valled);
  delay(500);
}


// --------------------------------
// Fonction traitement telecommande
// --------------------------------
void TraiteTeleco()
{
  if (irrecv.decode(&results)) 
  {
   valinfradec=results.value, DEC;
   lcd.setCursor(0,1);   
   switch (valinfradec) 
   {
     case 16753245:            // Arret depart clignotement LED
       bclignote=!bclignote;
       digitalWrite(Led,bclignote);
     break;
     
     case 16736925:            // Choix du mode
       TraiteMode();
     break;
     
     case 16738455:            // Chiffres 
       lcd.write("0");
     break;
     
     case 16724175:              
       lcd.write("1");
     break;
     
     case 16718055:
       lcd.write("2");
     break;

     case 16743045:
       lcd.write("3");
     break;
     
     case 16716015: 
       lcd.write("4");
     break;
     
     case 16726215:
       lcd.write("5");
     break;
     
     case 16734885:
       lcd.write("6");
     break;
     
     case 16728765:
       lcd.write("7");
     break;

     case 16730805:
       lcd.write("8");
     break;
     
     case 16732845:
       lcd.write("9");
     break;
     
     case 16748655:          // Touche +
       lcd.write("+");
     break;
     
     case 16754775:          // Touche -
       lcd.write("-");
     break;

   }
  
   // Resume  
   irrecv.resume(); // Receive the next value
  }
}


Aucun commentaire:

Enregistrer un commentaire