Objectifs

  1. Les variables locales
  2. Les variables globales
  3. Les variables statiques
  4. Les variables volatiles
  5. Exemples implémentés sur la carte Arduino Mega

Les variables locales

  • Portée limitée à la fonction
  • Non lisible à l’extérieur de la fonction

Les variables globales

  • Portée globales
  • Lisibles par toutes les fonctions

Variables statiques

  • Portée locales à la fonction
  • Non lisible à l’extérieur de la fonction
  • Maintient la valeur pour chaque appel de la fonction !!!!!!!!!!!

Variables volatiles = variables locales

Exemple

int a,b;




void setup() {

  Serial.begin(9600);

}




void loop() {

  // Variables locales

  /*Serial.println(a);

  delay(1000); */




  // Variables globales

  /*a=10; b=20;

  Serial.println(sum2IntGlob());

  delay(100);




  a=100; b=200;

  Serial.println(sum2IntGlob());

  delay(2000);*/







  // Variables statiques 

  /*for (int i=0;i<5;i++)

  {

    Serial.print(varStatic());

    Serial.print("  ");

    delay(200);

  }

  Serial.print("\n");

  delay(3000);*/




  // Variables volatiles 

  /*for (int i=0;i<5;i++)

  {

    Serial.print(varVolatile());

    Serial.print("  ");

    delay(200);

  }

  Serial.print("\n");

  delay(3000);*/

}




int sum2IntLoc(int a, int b)

{

  int somme;

  somme=a+b;

  return somme;

}







int sum2IntGlob(void)

{

  return a+b;

}




byte varStatic(void)

{

  static byte Count=0;

  return Count=Count+1;

}




byte varVolatile(void)

{

  volatile byte Count=0;

  return Count=Count+1;

}
Click to rate this post!
[Total: 1 Average: 1]

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

FPGA | Arduino | Matlab | Cours will use the information you provide on this form to be in touch with you and to provide updates and marketing.