[Résolu] Commande switch

Bonjour/Bonsoir à tous, j'ai d'un arduino Mega 2560. Je vous expose mon projet, je récupère la température grâce à un capteur LM35DZ, et j'ai envie d'afficher cette valeur deux 7segments.

Donc voilà le topo, le LM35DZ est branché sur l'AO, j'arrive à récupérer cette valeur et à l'afficher dans la console. j'ai deux 7segments controlé par les pins digitals.

Tout "marche" sauf ma commande switch, si je mets

switch('22')
  {
    
        case  '22' :

   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, HIGH);
   digitalWrite(I, HIGH);
   digitalWrite(J, LOW);
   digitalWrite(K, HIGH);
   digitalWrite(L, LOW);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);
   
   break;

Mes deux 7segments m'affiche bien 22.Mais si je met (temperature variable récupéré par le capteur) :

switch(temperature,DEC)
  {
    
        case  '22' :

   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, HIGH);
   digitalWrite(I, HIGH);
   digitalWrite(J, LOW);
   digitalWrite(K, HIGH);
   digitalWrite(L, LOW);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);
   
   break;

Rien ne s'affiche, je vois vraiment pas ou est le problème :/

Voici mon code en entier :

const int A = 12;
const int B = 11;
const int C = 10;
const int D = 9;
const int E = 8;
const int F = 7;
const int G = 6;

const int H = 30;
const int I = 32;
const int J = 34;
const int K = 36;
const int L = 38;
const int M = 40;
const int N = 42;


const char pin_capteur = A0;
char temperature_max=30;
char temperature_min=10;
char temperature=0;
float valeur_capteur;
char pleine_echelle=5;
int resolution=1024;
float pas=0.01;






void setup()
{
  
   Serial.begin(57600);

   pinMode(A, OUTPUT);
   pinMode(B, OUTPUT);
   pinMode(C, OUTPUT);
   pinMode(D, OUTPUT);
   pinMode(E, OUTPUT);
   pinMode(F, OUTPUT);
   pinMode(G, OUTPUT);
   

   pinMode(H, OUTPUT);
   pinMode(I, OUTPUT);
   pinMode(J, OUTPUT);
   pinMode(K, OUTPUT);
   pinMode(L, OUTPUT);
   pinMode(M, OUTPUT);
   pinMode(N, OUTPUT);
   
   
   pinMode(pin_capteur,INPUT);



   digitalWrite(A, LOW);
   digitalWrite(B, LOW);
   digitalWrite(C, LOW);
   digitalWrite(D, LOW);
   digitalWrite(E, LOW);
   digitalWrite(F, LOW);
   digitalWrite(G, LOW);
   
   digitalWrite(H, LOW);
   digitalWrite(I, LOW);
   digitalWrite(J, LOW);
   digitalWrite(K, LOW);
   digitalWrite(L, LOW);
   digitalWrite(M, LOW);
   digitalWrite(N, LOW);
}

void loop()

{



 valeur_capteur=analogRead(pin_capteur);
 temperature=(((valeur_capteur*pleine_echelle)/resolution)/pas);
 Serial.println(temperature,DEC);

 delay(1000);

  switch(temperature,DEC)
  {
    
        case  '22' :

   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, HIGH);
   digitalWrite(I, HIGH);
   digitalWrite(J, LOW);
   digitalWrite(K, HIGH);
   digitalWrite(L, LOW);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);
   
   break;
           case  '23' :
   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
    
   digitalWrite(H, LOW);
   digitalWrite(I, HIGH);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, LOW);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);


   break;
          case  '24' :
   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, LOW);
   digitalWrite(I, LOW);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, HIGH);
   digitalWrite(M, LOW);
   digitalWrite(N, HIGH);

   break;
          case  '25' :

   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, LOW);
   digitalWrite(I, HIGH);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, HIGH);
   digitalWrite(M, HIGH);
   digitalWrite(N, LOW);
   
   break;
          case  '26' :
   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, HIGH);
   digitalWrite(I, HIGH);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, HIGH);
   digitalWrite(M, LOW);
   digitalWrite(N, LOW);

   break;
          case  '27' :
   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);

   digitalWrite(H, LOW);
   digitalWrite(I, LOW);
   digitalWrite(J, HIGH);
   digitalWrite(K, LOW);
   digitalWrite(L, LOW);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);
   
   break;
          case  '28' :

   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
   digitalWrite(H, HIGH);
   digitalWrite(I, HIGH);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, HIGH);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);
   
   break;
          case  '29' :
   digitalWrite(A, HIGH);
   digitalWrite(B, HIGH);
   digitalWrite(C, LOW);
   digitalWrite(D, HIGH);
   digitalWrite(E, LOW);
   digitalWrite(F, HIGH);
   digitalWrite(G, HIGH);
   
    digitalWrite(H, LOW);
   digitalWrite(I, LOW);
   digitalWrite(J, HIGH);
   digitalWrite(K, HIGH);
   digitalWrite(L, HIGH);
   digitalWrite(M, HIGH);
   digitalWrite(N, HIGH);

  default :
  

     
   break;
   }
  
   
}

Merci !

Bonjour,

Erreur bête : 2 = valeur 2 en décimal '2' = caractére ASCII '2' (= 50 en décimal) "22" (double quotes) = chaine de caractére, en mémoire = { '2', '2', '\0' } mais '22' (simple quotes) = erreur de syntaxe

Dans ton cas il suffit d'enlever les quotes ;)

Merci ça marche :)