Objectifs

  1. Importance
  2. Comment définir et déclarer une structure
  3. Comment initialiser une structure
  4. Comment affecter les données à un champ de structure
  5. Comment lire les champs d’une structure
  6. Affectation de structures
  7. Structure et tableau
  8. Structure de structure (Exemple sur Arduino Mega)
  9. Etc.

Importance

  • Programmation modulaire
  • Généralisation de la notion des  types
  • Déclaration d’une variable multi-types
  • Regroupement des types

Comment définir et déclarer une structure

struct NomStruct

{

Type1 var1;

Type1 var1;

Type1 var1;

...;

};

Exemple

struct MoteurCC

{

float V;

float I;

float Temp;

bool  Etat;

bool  SurI;

bool  SurV;

bool  SurTemp;

};




MoteurCC M1, M2, M3;

Comment initialiser les champs d’une structure

M1.V=0.0;

M1.I=0.0;

M1.Temp=0.0;

M1.Etat=false;

Affectation des structures

M2=M1 =>

M2.V=M1.V;

M2.I=M1.I;

...;

Comment lire les champs d’une structure

float TempM1, CourM2;




TempM1=M1.Temp;

CourM2=M2.I

Structure et tableau

 

struct MCCBuffer

{

float V[10];

float I[10];

};




MCCBuffer MB1,MB2;

MB1.V[1]=0.0;

MB1.I[5]=0.0;




for (int i=0;i<10;i++)

{

MB1.V[i]=0;

MB2.V[i]=0;

}

Structure de structure

struct S1

{

int a1;

int b1;

};




struct S2

{

S1 a2;

S1 b2;

};

S1 ab;

S2 AB;




void setup() {

Serial.begin(9600);

}




void loop() {




// Init & Affichage S1

/*ab.a1=10; ab.b1=100;




Serial.println(ab.a1);

Serial.println(ab.b1);

delay(1000); */




// Init & Affichage S2

/*static byte count =0;

AB.a2.a1=count+1;

AB.b2.b1=count+2;

Serial.println("\n \n");

Serial.println(AB.a2.a1);

Serial.println(AB.b2.b1);

count+=1;

delay(1000);*/

}

Sujets connexes

  • Tableau de structure Arduino
  • Arduino functions
  • Arduino struct array
  • Arduino pointeur structure
  • Déclaration structure Arduino
  • Arduino enum
  • Fonction struct Arduino
  • Structure de données Arduino
Click to rate this post!
[Total: 0 Average: 0]

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.