Objectifs

  1. Importance
  2. Savoir manipuler les tableaux
  3. Savoir transformer un tableau 2D en 1D

Exemple

#define  m    5     // Lignes (2D)

#define  n    200     // Colonnes (2D) 

#define  MN   m*n   // Taille (1D)







int Tab2D[m][n];

int Tab1D[MN];




void setup() {




  // Init port série

  Serial.begin (9600);




  // Init tab 2

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

    for (int j=0; j<n; j++)

      Tab2D[i][j]=i*n+j;  




  // 2D => 1D

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

    for (int j=0; j<n; j++)

      Tab1D[i*n+j]=Tab2D[i][j]; 

}




void loop() {




  // Affichage 2D

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

  {

    for (int j=0; j<n; j++)

    {

      Serial.print(Tab2D[i][j]);

      Serial.print(" ");

      delay(10);

    }

    Serial.print("\n");

  }

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




  // Affichage 1D

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

  {

    Serial.print(Tab1D[i]);

    Serial.print(" ");

    delay(10);

  }

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

  delay(20000);

}
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.