<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Débutant Arduino Archives - PlaisirArduino</title>
	<atom:link href="https://plaisirarduino.fr/category/debutant-arduino/feed/" rel="self" type="application/rss+xml" />
	<link>https://plaisirarduino.fr/category/debutant-arduino/</link>
	<description></description>
	<lastBuildDate>Sun, 10 Aug 2025 12:18:52 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>La persistance des données EEPROM</title>
		<link>https://plaisirarduino.fr/la-persistance-des-donnees-eeprom/</link>
		
		<dc:creator><![CDATA[Eugénio DA-LUZ]]></dc:creator>
		<pubDate>Sun, 10 Aug 2025 09:54:10 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=4913</guid>

					<description><![CDATA[<p>1. Objectif pédagogique À la fin de ce cours, vous saurez : Précaution à prendre En quelque minutes les cellules EEPROM peuvent se détérioré et altéré votre carte. 2. Présentation de L'EEPROM Qu’est‑ce que l’EEPROM ?L’EEPROM (Electrically Erasable Programmable Read-Only Memory) est une mémoire&#160;non volatile&#160;: elle garde les données même &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/la-persistance-des-donnees-eeprom/">La persistance des données EEPROM</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="EEPROM Arduino : Gardez vos données au redémarrage !" width="660" height="371" src="https://www.youtube.com/embed/BSWSgJ5_AOc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading">1. Objectif pédagogique</h2>



<p>À la fin de ce cours, vous saurez :</p>



<ul class="wp-block-list">
<li>Comprendre le rôle et les limites de l’EEPROM interne d’un Arduino.</li>



<li>Lire et écrire des données persistantes avec&nbsp;<code class="" data-line="">EEPROM.read()</code>&nbsp;et&nbsp;<code class="" data-line="">EEPROM.write()</code>.</li>



<li>Optimiser les écritures avec&nbsp;<code class="" data-line="">EEPROM.update()</code>.</li>



<li>Sauvegarder et relire des variables complètes avec&nbsp;<code class="" data-line="">EEPROM.put()</code>&nbsp;et&nbsp;<code class="" data-line="">EEPROM.get()</code>.</li>



<li>Créer un projet simple qui conserve ses paramètres après extinction.</li>
</ul>



<h2 class="wp-block-heading">Précaution à prendre</h2>



<p>En quelque minutes les cellules EEPROM peuvent se détérioré et altéré votre carte.</p>



<h2 class="wp-block-heading">2. Présentation de L'EEPROM</h2>



<p><strong>Qu’est‑ce que l’EEPROM ?</strong><br>L’EEPROM (Electrically Erasable Programmable Read-Only Memory) est une mémoire&nbsp;<em>non volatile</em>&nbsp;: elle garde les données même sans alimentation. </p>



<p><strong>Caractéristiques :</strong></p>



<ul class="wp-block-list">
<li>Capacité limitée : ex. 1024 octets sur un Arduino Uno.</li>



<li>Accès octet par octet ou via des variables complètes.</li>



<li>Durée de vie ~100 000 écritures par cellule (éviter les écritures inutiles).</li>
</ul>



<p><strong>Applications :</strong>&nbsp;sauvegarde de paramètres, compteurs, scores, restauration d’état après redémarrage.</p>



<h2 class="wp-block-heading">3. Matériel nécessaire</h2>



<ul class="wp-block-list">
<li>Arduino Uno (ou Nano, Mega…)</li>



<li>Câble USB</li>



<li>(Optionnel) Bouton poussoir + résistance 10 kΩ</li>



<li>(Optionnel) LED + résistance 220 Ω</li>
</ul>



<p><strong>Schéma minimaliste :</strong>&nbsp;pour les premiers exemples, aucun câblage n’est requis.</p>



<h2 class="wp-block-heading">4. Explication du fonctionnement</h2>



<p>L’EEPROM est organisée en cases numérotées (adresses). Chaque case stocke un octet (0–255). Imaginez un meuble avec 1024 tiroirs : chaque tiroir peut contenir un petit papier avec un nombre. Quand vous éteignez l’Arduino, les papiers restent en place.</p>



<h2 class="wp-block-heading">5. Premier code minimaliste</h2>



<p>Exemple simple : écrire puis lire un octet à l’adresse 0.</p>



<pre class="wp-block-code"><code class="" data-line="">#include &lt;EEPROM.h&gt;

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

  // Écrire 42 à l&#039;adresse 0
  EEPROM.write(0, 42);

  // Lire la valeur stockée à l&#039;adresse 0
  byte valeur = EEPROM.read(0);

  Serial.print(&quot;Valeur lue : &quot;);
  Serial.println(valeur);
}

void loop() {
  // Vide
}
</code></pre>



<p><strong>Ce que fait ce code :</strong>&nbsp;écrit le nombre 42 à l'adresse 0, puis le relit et l'affiche sur le moniteur série.</p>



<h2 class="wp-block-heading">6. Décryptage du code</h2>



<ul class="wp-block-list">
<li><code class="" data-line="">#include &lt;EEPROM.h&gt;</code>&nbsp;: active la bibliothèque EEPROM.</li>



<li><code class="" data-line="">EEPROM.write(adresse, valeur)</code>&nbsp;: écrit un octet.</li>



<li><code class="" data-line="">EEPROM.read(adresse)</code>&nbsp;: lit un octet.</li>



<li>Les adresses vont de&nbsp;<code class="" data-line="">0</code>&nbsp;à&nbsp;<code class="" data-line="">EEPROM.length()-1</code>.</li>



<li>Erreur fréquente : écrire trop souvent (surtout dans&nbsp;<code class="" data-line="">loop()</code>) use la mémoire.</li>
</ul>



<h2 class="wp-block-heading">7. Expérimentation guidée</h2>



<p>Propositions faciles :</p>



<ul class="wp-block-list">
<li>Changer la valeur écrite (ex.&nbsp;<code class="" data-line="">EEPROM.write(0, 100)</code>).</li>



<li>Utiliser une autre adresse (ex. adresse 10).</li>



<li>Écrire plusieurs valeurs et les relire.</li>
</ul>



<h2 class="wp-block-heading">8. Fonctions avancées</h2>



<p>En complément de&nbsp;<code class="" data-line="">read()</code>&nbsp;et&nbsp;<code class="" data-line="">write()</code>, Arduino fournit :</p>



<h3 class="wp-block-heading">EEPROM.update(adresse, valeur)</h3>



<p>Écrit seulement si la valeur est différente de celle déjà stockée — utile pour économiser les cycles d'écriture.</p>



<pre class="wp-block-code"><code class="" data-line="">#include &lt;EEPROM.h&gt;

void setup() {
  Serial.begin(9600);
  EEPROM.update(0, 42); // Écrit seulement si nécessaire
  Serial.println(&quot;Valeur mise à jour !&quot;);
}

void loop() {}
</code></pre>



<h3 class="wp-block-heading">EEPROM.put(adresse, variable)</h3>



<p>Permet d'enregistrer une variable complète (int, float, struct...) en une seule instruction.</p>



<pre class="wp-block-code"><code class="" data-line="">#include &lt;EEPROM.h&gt;

struct Donnees {
  int compteur;
  float temperature;
};

Donnees info;

void setup() {
  Serial.begin(9600);
  info.compteur = 123;
  info.temperature = 24.5;
  EEPROM.put(0, info);
  Serial.println(&quot;Données sauvegardées !&quot;);
}

void loop() {}
</code></pre>



<h3 class="wp-block-heading">EEPROM.get(adresse, variable)</h3>



<p>Lit directement une variable complète depuis l'EEPROM (complément de&nbsp;<code class="" data-line="">put</code>).</p>



<pre class="wp-block-code"><code class="" data-line="">#include &lt;EEPROM.h&gt;

struct Donnees {
  int compteur;
  float temperature;
};

Donnees info;

void setup() {
  Serial.begin(9600);
  EEPROM.get(0, info);
  Serial.print(&quot;Compteur : &quot;);
  Serial.println(info.compteur);
  Serial.print(&quot;Température : &quot;);
  Serial.println(info.temperature);
}

void loop() {}
</code></pre>



<p>Astuce :&nbsp;<code class="" data-line="">put()</code>&nbsp;et&nbsp;<code class="" data-line="">get()</code>&nbsp;gèrent automatiquement la taille en octets — attention à la place restante dans l'EEPROM.</p>



<h2 class="wp-block-heading">9. Vérification avant écriture dans l’EEPROM</h2>



<p>Avant d’enregistrer une donnée en mémoire EEPROM, il est essentiel de vérifier que sa valeur a réellement changé. En effet, si la donnée est identique à celle déjà stockée, une réécriture inutile détériorera prématurément la cellule mémoire, qui ne supporte qu’un nombre limité de cycles d’écriture. Pour protéger la durée de vie de l’EEPROM, il faut donc ajouter systématiquement une étape de vérification avant d’écrire.</p>



<p>Voici un exemple fiable et simple, utilisable pour tout type de donnée basique (comme un octet) :</p>



<pre class="wp-block-code"><code class="" data-line="">
#include &lt;EEPROM.h&gt;

int adresse = 0;         // Adresse mémoire EEPROM
byte nouvelleValeur = 42; // Valeur à écrire

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

  // Lire la valeur actuelle dans l’EEPROM
  byte ancienneValeur = EEPROM.read(adresse);

  // Vérifier si la valeur a changé avant d’écrire
  if (ancienneValeur != nouvelleValeur) {
    EEPROM.write(adresse, nouvelleValeur);
    Serial.println(&quot;Valeur mise à jour dans l’EEPROM.&quot;);
  } else {
    Serial.println(&quot;Valeur identique, écriture évitée pour préserver l’EEPROM.&quot;);
  }
}

void loop() {
  // Rien ici
}
</code></pre>



<p>Cette méthode simple protège efficacement l’EEPROM contre les écritures redondantes et prolonge sa durée de vie.</p>



<h2 class="wp-block-heading">Exemple fiable de vérification avant écriture avec EEPROM.get() et EEPROM.put()</h2>



<p>Pour éviter d’écrire inutilement dans l’EEPROM une structure&nbsp;<code class="" data-line="">Donnees</code>, on peut comparer la donnée à écrire avec celle déjà stockée, puis n’écrire que si elles diffèrent.</p>



<pre class="wp-block-code"><code class="" data-line="">#include &lt;EEPROM.h&gt;

struct Donnees {
  int compteur;
  float temperature;
};

Donnees infoNew;  // Nouvelle donnée à sauvegarder
Donnees infoOld;  // Donnée lue depuis EEPROM

void setup() {
  Serial.begin(9600);
  delay(1000); // Attente pour le moniteur série

  // Initialisation des nouvelles données
  infoNew.compteur = 123;
  infoNew.temperature = 24.5;

  // Lire la donnée existante dans EEPROM à l&#039;adresse 0
  EEPROM.get(0, infoOld);

  // Comparer byte à byte pour vérifier si les données ont changé
  if (memcmp(&amp;infoNew, &amp;infoOld, sizeof(Donnees)) != 0) {
    EEPROM.put(0, infoNew);
    Serial.println(&quot;Données mises à jour dans l’EEPROM.&quot;);
  } else {
    Serial.println(&quot;Données identiques, écriture évitée.&quot;);
  }
}

void loop() {
  // Rien ici
}
</code></pre>



<h2 class="wp-block-heading">10. Résumé</h2>



<ul class="wp-block-list">
<li>Lecture/écriture d'octets :&nbsp;<code class="" data-line="">read()</code>&nbsp;/&nbsp;<code class="" data-line="">write()</code>.</li>



<li>Éviter les écritures inutiles :&nbsp;<code class="" data-line="">update()</code>.</li>



<li>Stocker/charger des variables complètes :&nbsp;<code class="" data-line="">put()</code>&nbsp;/&nbsp;<code class="" data-line="">get()</code>.</li>



<li>Penser à la taille disponible et à l'usure des cellules.</li>
</ul>



<h2 class="wp-block-heading">Ressources complémentaires</h2>



<ul class="wp-block-list">
<li>Documentation officielle :&nbsp;<a href="https://www.arduino.cc/en/Reference/EEPROM" target="_blank" rel="noreferrer noopener">arduino.cc — EEPROM</a></li>



<li>Bibliothèque&nbsp;<code class="" data-line="">EEPROM.h</code>&nbsp;incluse par défaut</li>



<li>Conseil pratique : limiter les écritures inutiles pour préserver la mémoire</li>
</ul>
<p>Cet article <a href="https://plaisirarduino.fr/la-persistance-des-donnees-eeprom/">La persistance des données EEPROM</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ruban à l&#8217;LED adressable</title>
		<link>https://plaisirarduino.fr/ruban-a-led-adressable/</link>
		
		<dc:creator><![CDATA[Eugénio DA-LUZ]]></dc:creator>
		<pubDate>Tue, 30 Jan 2024 21:46:14 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=4805</guid>

					<description><![CDATA[<p>Caractéristiques du ruban à LED adressage Type: WS2812B Alimentation: 18 mA/LED 5V ne supporte pas les surtensions, une alimentation stable est recommandée. La bibliothèque de gestion des LEDs que j'ai utilisée est "Adafruit_NeoPixel.h". Le projet est relativement simple à mettre en oeuvre sur un petit nombre de LEDs. J'ai pris &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/ruban-a-led-adressable/">Ruban à l&rsquo;LED adressable</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Ruban à led addressable avec arduino" width="660" height="371" src="https://www.youtube.com/embed/w8bx2bhkvsw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading has-text-align-center">Caractéristiques du ruban à LED adressage</h2>



<p> Type:  WS2812B</p>



<p>Alimentation: 18 mA/LED 5V ne supporte pas les surtensions, une alimentation stable est recommandée.</p>



<figure class="wp-block-image size-large"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led.png"><img fetchpriority="high" decoding="async" width="1024" height="476" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-1024x476.png" alt="" class="wp-image-4806" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-1024x476.png 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-300x139.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-768x357.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-1536x714.png 1536w, https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-2048x951.png 2048w, https://plaisirarduino.fr/arduino/wp-content/uploads/2024/01/schema-ruban-a-led-700x325.png 700w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>La bibliothèque de gestion des LEDs  que j'ai utilisée est "Adafruit_NeoPixel.h".</p>



<p>Le projet est relativement simple à mettre en oeuvre sur un petit nombre de LEDs. J'ai pris comme point de départ l'exemple "simple" que j'ai retravaillé. </p>



<p class="has-text-align-left">La bibliothèque Adafruit NeoPixel pour Arduino est conçue pour faciliter la gestion des LED RGB individuelles ou des bandes de LED RGB, telles que les populaires LED WS2812 ou WS2812B. Voici quelques-unes des fonctions natives de cette bibliothèque :</p>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">Adafruit_NeoPixel pixels(nombre de pixels, branche de sortie, neoPixelType type)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Initialise la bibliothèque en spécifiant le nombre total de pixels, le numéro de broche à laquelle les pixels sont connectés et le type de pixels (par exemple, <code class="" data-line="">NEO_GRB</code> ou <code class="" data-line="">NEO_RGB</code>).</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">begin()</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Initialise la communication avec les pixels. Cette fonction doit être appelée une fois dans le programme, généralement dans la fonction <code class="" data-line="">setup()</code>.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">show()</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Envoie les données de couleur aux pixels. Vous devez appeler cette fonction après avoir modifié les couleurs des pixels pour les rendre effectives.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">setPixelColor(numéro de la LED adressable, couleur rouge de 0 à 255, couleur vert de 0 à 255, &lt;strong&gt;&lt;code&gt;couleur bleu de 0 à 255</code></strong>)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Définit la couleur d'un pixel spécifique en spécifiant les valeurs des composants rouge, vert et bleu (RVB). Les valeurs des composants RVB vont de 0 à 255.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">setPixelColor(uint16_t n, uint32_t color)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Version alternative de <code class="" data-line="">setPixelColor</code> où vous spécifiez directement la couleur sous forme d'un entier 32 bits, où les 8 premiers bits représentent le rouge, les 8 suivants le vert et les 8 derniers le bleu.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">setBrightness(intensité de 0 à 255)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Ajuste la luminosité de tous les pixels. La valeur de luminosité varie de 0 (éteint) à 255 (pleine luminosité).</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">Color(uint8_t red, uint8_t green, uint8_t blue)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Fonction utilitaire qui renvoie une couleur sous forme d'entier 32 bits à partir des composants RVB spécifiés.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">ColorHSV(uint16_t hue, uint8_t saturation, uint8_t value)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Fonction utilitaire qui renvoie une couleur sous forme d'entier 32 bits à partir des composants HSV (teinte, saturation, valeur) spécifiés.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">getPixelColor(uint16_t n)</code></strong></li>
</ol>



<ul class="wp-block-list">
<li>Récupère la couleur d'un pixel spécifique sous forme d'entier 32 bits.</li>
</ul>



<ol class="wp-block-list">
<li><strong><code class="" data-line="">clear()</code></strong>
<ul class="wp-block-list">
<li>Éteint tous les pixels en les mettant à la couleur noire (0, 0, 0).</li>
</ul>
</li>
</ol>



<p>Ces fonctions de base devraient vous aider à démarrer avec la gestion des LEDs à l'aide de la bibliothèque Adafruit NeoPixel dans vos projets Arduino. N'oubliez pas de consulter la documentation officielle pour des détails plus approfondis sur chaque fonction : https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library.</p>



<p>Merci pour votre intérêt, vous pouvez revoir toutes les vidéos sur la chaine Youtube <a href="https://www.youtube.com/@plaisirarduino6659">plaisirarduino</a></p>



<p></p>
<p>Cet article <a href="https://plaisirarduino.fr/ruban-a-led-adressable/">Ruban à l&rsquo;LED adressable</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bibliothèque, comment l&#8217;explorer ?</title>
		<link>https://plaisirarduino.fr/explorer-une-bibliotheque/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Tue, 18 Apr 2017 18:09:35 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=2344</guid>

					<description><![CDATA[<p>Explorer une bibliothèque. La bibliothèque est incontournable dans l'univers Arduino pour l'exploitation de multiple composants ou la gestion de communication entre composants et l'Arduino. Vous avez sûrement déjà utilisé &#60;&#60;LiquidCrystal.h&#62;&#62; pour un afficheur LCD ou &#60;&#60;Servo.h&#62;&#62; pour des servomoteurs et &#60;&#60;SPI.h&#62;&#62; pour le traitement de la communication SPI. Mais, il y en &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/explorer-une-bibliotheque/">Bibliothèque, comment l&rsquo;explorer ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Explorer une bibliothèque.</span> </span></strong></h1>
<p style="text-align: justify;">La bibliothèque est incontournable dans l'univers Arduino pour<strong> l'exploitation de multiple composants ou la gestion de communication</strong> entre composants et l'Arduino. Vous avez sûrement déjà utilisé <strong>&lt;&lt;<span style="color: #ff6600;">LiquidCrystal</span>.h&gt;&gt; pour un afficheur LCD </strong> ou <strong>&lt;&lt;<span style="color: #ff6600;">Servo</span>.h&gt;&gt;</strong> <strong>pour des servomoteurs</strong> et <strong>&lt;&lt;<span style="color: #ff6600;">SPI</span>.h&gt;&gt;</strong> pour le traitement de la <strong>communication SPI</strong>. Mais, il y en a bien d'autres.</p>
<p style="text-align: justify;">Avant toute chose , il faut préalablement <span style="text-decoration: underline;"><em><strong><span style="color: #33cccc;"><a style="color: #33cccc; text-decoration: underline;" href="https://plaisirarduino.fr/bibliotheque/">installer puis inclure la bibliothèque </a></span></strong></em></span>dans notre programme<strong>.</strong></p>
<p style="text-align: justify;">Tout comme vous, à mes débuts, je me suis fié aux divers exemples trouvés dans l'IDE ou sur le net sans me demander<strong> pourquoi et</strong> <strong>comment on utilisait les bibliothèques</strong>. Puis avec l'expérience, je me suis documenté et me suis aperçu que je n'exploitais qu'à moitié certaines bibliothèques alors qu'elles me<strong> proposaient d'autres possibilités intéressantes</strong>.</p>
<p style="text-align: justify;">C'est pour cela donc, que dans ce tutoriel, nous allons <strong><span style="text-decoration: underline;">apprendre à "lire" une bibliothèque et identifier ce dont il nous faut pour son exploitation optimale.<br />
</span></strong></p>
<p style="text-align: justify;">Nous explorerons la bibliothèque <strong>&lt;&lt;<span style="color: #ff6600;">Servo</span>.h&gt;&gt; </strong>pour nos exemples.</p>
<h4 style="text-align: justify;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">De quoi est composé une bibliothèque ?</span></span></strong></h4>
<p style="text-align: justify;">En fait, <strong>c'est un dossier</strong>. Il contient des dossiers et fichiers de<strong> code programme</strong>. Il y a principalement trois fichiers et un dossier à explorer.</p>
<ul style="text-align: justify;">
<li><strong>Le fichier d'entête</strong>. Repérable par ".h"</li>
<li><strong>Le fichier sources</strong>. Repérable par ".cpp"</li>
<li><strong>Le dossier "exemple"</strong>. Qui contient des codes sources en exemple d'utilisation.</li>
<li><strong>Le fichier de syntaxe des couleurs</strong>. Qui contient les consignes de couleurs à appliquer pour chaque type de mots-clés.</li>
</ul>
<p style="text-align: justify;">Ici, nous nous concentrerons particulièrement sur <strong>le fichier d'entête, </strong>Puis nous verrons le fichier "exemple" et "syntaxe".</p>
<h4><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">Comment explorer une bibliothèque ?</span></strong></span></h4>
<p style="text-align: justify;">Tout d'abord, commencez par rechercher et trouver <strong>le fichier d'entête</strong> de la bibliothèque qui est en l’occurrence pour nos exemples <strong>"Servo.h"</strong>.</p>
<p style="text-align: justify;">Deux solutions pour trouver ce fichier.</p>
<h4><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/08-Bibliotheque.png" alt="08 - Bibliotheque" width="154" height="168" /></h4>
<h6><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Première solution.</span></span></strong></h6>
<p><img loading="lazy" decoding="async" class="alignleft" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/07-Bibliotheque.png" alt="07 - Bibliotheque" width="56" height="40" />Exécutez une <strong>recherche de fichiers depuis le menu "DÉMARRER"</strong> en tapant "Servo.h".  Ensuite, ouvrez-le et <strong>suivez les étapes 5 et 6 de la solution suivante.</strong></p>
<h6><img loading="lazy" decoding="async" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/06-Bibliotheque.png" alt="06 - Bibliotheque" width="295" height="135" /></h6>
<h6><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Deuxième solution.</span></span></strong></h6>
<ol>
<li style="text-align: justify;">Premièrement, <span style="text-decoration: underline;">si vous n'avez pas modifié son emplacement par défaut à l'installation</span>, allez sur vôtre<strong> disque local "C:" dans le dossier "programme files".</strong></li>
<li style="text-align: justify;">Ensuite, ouvrez le dossier "<strong>Arduino</strong>"</li>
<li style="text-align: justify;">Puis, le dossier "<strong>libraries</strong>".</li>
<li style="text-align: justify;">Après, le dossier "<strong>Servo</strong>".</li>
<li style="text-align: justify;">Ouvrir le dossier "<strong>src</strong>".</li>
<li style="text-align: justify;">Finalement, le fichier "<strong>Servo</strong>.<strong>h</strong>" apparaît.</li>
</ol>
<h4><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">Explorons le fichier.</span></strong></span></h4>
<p style="text-align: justify;">Une fois que vous avez trouvé l'emplacement du fichier "Servo.h", ouvrez-le.</p>
<p style="text-align: justify;">A première vue, on a pas l'impression que ce fichier est un code programme car il est <strong>présenté sous format" texte".</strong> De ce fait, il est exploitable par un éditeur de texte comme "NotePad", "WordPad" ou le "Bloc-notes".</p>
<p style="text-align: justify;">De toute évidence, vous constaterez qu'il est en anglais. Donc pour cette étape, un <strong>travail de traduction des commentaires sera très utile à la compréhension</strong> du programme. Je vous invite donc à le faire avec un traducteur de votre choix.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;"><strong><span style="color: #ff0000; text-decoration: underline;">Ne surtout pas apporter de modifications à ce document! </span>Surtout si vous n'avez pas d'idée précise de ce que vous faite.</strong></span> Alors dans ce cas, ne<strong><span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;"> JAMAIS accepter d'enregistrer des modifications</span></span> </strong>car cela entraînerait le dysfonctionnement de la bibliothèque et provoquerait des erreurs lors du téléversement.</p>
<p style="text-align: justify;">Mais <strong>quel est son rôle ?</strong></p>
<h4 style="text-align: justify;"><strong><span style="text-decoration: underline; color: #0000ff;">le rôle du fichier d'entête. </span></strong></h4>
<p style="text-align: justify;">Le rôle du fichier d'en-tête est de <strong>mettre en place la structure principale de la bibliothèque.</strong> Il informe le compilateur de tout ce qu'il lui faut pour exécuter la bibliothèque et va en quelque sorte <strong>s'occuper de "déclarer"</strong>. Il n'y a <strong>pas d'exécution de fonctions,</strong> <strong>ces dernières se font dans le fichier source</strong> ".<strong>cpp</strong>".</p>
<p style="text-align: justify;">On dit qu'il contient <strong>le prototype de la bibliothèque.</strong></p>
<p style="text-align: justify;"> Clairement,  nous avons découpé le fichier en plusieurs parties.</p>
<ul>
<li>La présentation.</li>
<li>L'inclusion.</li>
<li>La déclaration.</li>
<li>La classe.</li>
</ul>
<h4><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Les grandes parties du fichier d'entête ".h"</span></span></strong></h4>
<h6><strong><span style="text-decoration: underline; color: #0000ff;">1) La présentation.</span></strong></h6>
<p style="text-align: justify;">En somme, après traduction, elle vous indique<strong> la version, le ou les auteurs, ainsi que les conditions générales d'utilisation (GNU).</strong> C'est obligatoire et recommandé pour la distribution.</p>
<p><img loading="lazy" decoding="async" class="wp-image-2468 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/09-Bibliotheque.png" alt="09 - Bibliotheque" width="675" height="257" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/09-Bibliotheque.png 954w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/09-Bibliotheque-300x114.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/09-Bibliotheque-768x292.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/09-Bibliotheque-700x266.png 700w" sizes="auto, (max-width: 675px) 100vw, 675px" /></p>
<p>Il faut aussi souligner que ce texte est un commentaire balisé par ceci  "/* */" ce qui vous permet d'identifier la première partie de la présentation générale.</p>
<p>Ensuite, vous avez une seconde partie. L’aspect le plus important de cette partie, c'est qu'elle <strong>décrit le fonctionnement globale de la bibliothèque.</strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-2472 size-full aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108.png" alt="10 - Bibliotheque" width="1408" height="538" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108.png 1408w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108-300x115.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108-768x293.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108-1024x391.png 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-Bibliotheque-e1490024090108-700x267.png 700w" sizes="auto, (max-width: 1408px) 100vw, 1408px" /></p>
<p style="text-align: justify;">Cependant, toutes les bibliothèques ne le font pas. Dans celle-ci sont citées et mentionnées avec un descriptif, toutes les <strong><span style="color: #000000;">méthodes, dont vous avez besoin pour exploiter vos programmes. </span></strong><span style="color: #000000;">N</span>ous y viendrons en détail par la suite.</p>
<p style="text-align: justify;">Après la présentation, poursuivons à présent, vers<strong> le code programme</strong> qui s'en suit.</p>
<h6 style="text-align: justify;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">2) L'inclusion.</span></span></strong></h6>
<p style="text-align: justify;">Voyons tout d'abord, les lignes du code ci-dessous.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2474" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/12-Bibliotheque.png" alt="12 - Bibliotheque" width="247" height="82" /></p>
<p style="text-align: justify;">Les deux premières lignes <strong>permettent au compilateur l'inclusion de la bibliothèque</strong> dans votre projet. La troisième ligne quand à elle inclue au sein même de la bibliothèque une autre bibliothèque.</p>
<p style="text-align: justify;">Par contre, <strong>"ifndef"</strong> signifie en anglais "<strong>if not defined</strong>" soit en français <strong>"si n'est pas défini". </strong>Nous avons donc là une condition "<span style="text-decoration: underline;"><strong><em><span style="color: #ff0000; text-decoration: underline;">if</span></em></strong></span>". Cette condition permet lors de la compilation d'un programme de <strong>ne pas systématiquement la compiler</strong>. On trouve ici un exemple important, à savoir, que l'on a une <strong>compilation conditionnelle des bibliothèques.</strong></p>
<p style="text-align: justify;">Par conséquent, suite à notre condition d’exécution, il faut bien-sûr indiquer au compilateur <strong>quoi exécuter !!</strong></p>
<p style="text-align: justify;">Cela ce fait avec l'instruction #<strong>endif. </strong>"<strong>end</strong><strong>if</strong>" qui signifie en français "<strong>fin</strong> <strong>de</strong> <strong>si</strong>". On comprend que la condition d'exécution s’arrête là.<strong> On trouve cette instruction à la fin du fichier d'entête.</strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-2476 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-Bibliotheque.png" alt="13 - Bibliotheque" width="505" height="116" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-Bibliotheque.png 700w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-Bibliotheque-300x69.png 300w" sizes="auto, (max-width: 505px) 100vw, 505px" /></p>
<p style="text-align: justify;">J'attire votre attention sur le fait que <span style="text-decoration: underline;"><strong>tout le programme du fichier d'entête est contenu dans ces instructions.</strong></span> Vous le constaterez en explorant le fichier.<span style="text-decoration: underline;"><strong><br />
</strong></span></p>
<p style="text-align: justify;">Poursuivons vers la partie suivante.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2478 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-Bibliotheque.png" alt="14 - Bibliotheque" width="721" height="176" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-Bibliotheque.png 721w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-Bibliotheque-300x73.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-Bibliotheque-700x171.png 700w" sizes="auto, (max-width: 721px) 100vw, 721px" /></p>
<p style="text-align: justify;">Celle-ci fait appel aux <strong>versions d'Arduino utilisées AVR SAM ou SAMD.</strong> Effectivement, il existe plusieurs versions possibles de compilations. De ce fait, le compilateur doit donc<strong> être capable de s'adapter aux divers environnements d'exploitation proposés</strong>. Mais là aussi, nous n’approfondirons pas. Sachez juste que cette partie<strong> définie votre environnement de travail pour adapter le travail du compilateur.</strong></p>
<p style="text-align: justify;">Vous avez sans doute remarqué les instructions suivantes. #<strong>if</strong> <strong>defined</strong> pour <span style="text-decoration: underline;">si définis</span>, #<strong>elif defined</strong> pour <span style="text-decoration: underline;">si non définis</span>, #<strong>else</strong> pour <span style="text-decoration: underline;">sinon</span> et finalement <strong>#endif</strong> pour <span style="text-decoration: underline;">fin de if.</span> Vous l'avez compris, c'est <strong>un ensemble d’instructions conditionnelles en fonction des versions possibles.</strong></p>
<h6><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">3) Les déclarations.</span></strong></span></h6>
<p style="text-align: justify;">A ce niveau du programme, nous avons deux<strong> parties distinctes</strong>. Les <span style="color: #0000ff;"><span style="color: #008000;">variables</span> </span>et la <span style="color: #0000ff;">classe</span>. Nous décomposerons donc cette partie en deux et nous ignorerons celle encadrée en noir qui nous est étrangère. <em> Les commentaires ont été traduit p</em><em>our une approche plus compréhensible.</em></p>
<p><img loading="lazy" decoding="async" class="wp-image-2502 size-full aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630.png" alt="21 - Bibliotheque" width="1418" height="666" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630.png 1418w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630-300x141.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630-768x361.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630-1024x481.png 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/21-Bibliotheque-e1490277874630-700x329.png 700w" sizes="auto, (max-width: 1418px) 100vw, 1418px" /></p>
<h6><strong><span style="text-decoration: underline; color: #0000ff;">3.1) Les variables.</span></strong></h6>
<p style="text-align: justify;">En premier lieu, nous avons les <em><span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">déclarations de variables</span></span></em> utiles au traitement de tout programme. A cette étape de notre exemple, on intègre une donnée à chaque variable.</p>
<h6><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">3.2) La classe.<br />
</span></span></strong></h6>
<p style="text-align: justify;">Finalement, nous voici dans <strong>la "déclaration" de ce que l'on appelle une <span style="color: #0000ff;">classe</span></strong>.</p>
<p style="text-align: justify;">L'instruction "<strong>class" </strong><strong>et son bloc d'instructions "{ }"</strong> <strong>permet de nommer et de créer une <span style="color: #ff0000;">classe</span>.</strong> Dans notre exemple ci-dessous elle est nommée <span style="color: #000000;"><strong>Servo</strong></span>.</p>
<p style="text-align: justify;"><strong><span style="color: #0000ff;">class</span> Servo<span style="color: #008000;"> { Bloc d'instructions à exécuter }</span>; </strong>// Déclaration d'une classe.</p>
<p style="text-align: justify;">Une fois nommée,<strong> la classe <span style="text-decoration: underline;">permettra d'initialiser un objet</span> auquel elle sera rattachée pour<span style="color: #000000;"> que ce dernier puisse faire appel au constructeur et aux méthodes qu'elle contient.<br />
</span></strong><span style="color: #000000;">Cela étant dit une classe peut être aussi utilisée sans objet.<br />
</span></p>
<p style="text-align: justify;">Examinez l'illustration ci-dessous.</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class=" wp-image-2517 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/24-Bibliotheque.png" alt="24 - Bibliotheque" width="355" height="245" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/24-Bibliotheque.png 495w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/24-Bibliotheque-300x207.png 300w" sizes="auto, (max-width: 355px) 100vw, 355px" />Notamment, il y a <strong><span style="color: #008000;">deux parties très importantes</span></strong> de la "<strong>classe</strong>". La partie "<strong><span style="color: #008000;">public<span style="color: #000000;">:</span></span></strong><span style="color: #008000;"><span style="color: #000000;">"</span></span> et <span style="color: #008000;"><span style="color: #000000;">"</span></span><strong><span style="color: #008000;">private<span style="color: #000000;">:</span></span></strong><span style="color: #008000;"><span style="color: #000000;">"</span></span>. En français<strong> <span style="text-decoration: underline;">public et privé</span></strong>. Mais en fait leur véritable nom est <strong><span style="color: #008000;">modificateurs d'accès</span>.</strong> Comme le nom l'indique, <strong>ils conditionnent l'accès ou non à certaines </strong>instructions utilisées à l’intérieur de la classe.<span style="text-decoration: underline;"><br />
</span></p>
<p style="text-align: justify;"><strong><span style="color: #008000;">Public <span style="color: #000000;">permet aux utilisateurs</span></span></strong><span style="color: #008000;"><span style="color: #000000;"> au travers de l'IDE</span></span><strong><span style="color: #008000;"><span style="color: #000000;"> d’accéder aux instructions qui lui sont confiées</span></span></strong>. Par contre <strong><span style="color: #008000;">private<span style="color: #000000;"> interdit l'accès aux instructions qui lui sont <span style="color: #008000;">confiées.</span></span></span></strong></p>
<p style="text-align: justify;">Observons ensuite la partie <span style="color: #008000;">public. <span style="color: #000000;">N</span></span>ous avons, le <strong><span style="color: #ff0000;">constructeur</span>. </strong></p>
<h5><strong><span style="text-decoration: underline; color: #ff0000;">3.2.1) Le Constructeur.</span></strong></h5>
<p><img loading="lazy" decoding="async" class="wp-image-2520 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23-Bibliotheque-e1490300488555.png" alt="23 - Bibliotheque" width="320" height="221" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23-Bibliotheque-e1490300488555.png 495w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23-Bibliotheque-e1490300488555-300x207.png 300w" sizes="auto, (max-width: 320px) 100vw, 320px" /></p>
<p style="text-align: justify;">Vous le reconnaîtrez par le fait qu'<span style="text-decoration: underline;"><strong>il porte le nom de la classe</strong></span><strong> suivi de parenthèses</strong> (comme pour un appel de <em>fonction</em>) et qu'il est<strong> placé juste après l'instruction "<span style="color: #008000;">public</span>:".</strong> Notez que, dans notre exemple ci-dessus, il ne possède aucun paramètre.</p>
<p style="text-align: justify;"><strong>Contrairement à notre exemple "servo", i</strong>l est possible que dans d'autres librairies, vous trouviez<strong> plusieurs constructeurs qui portent le même nom.</strong> Si vous observez (entre parenthèses) vous constaterez que ces librairies n'ont <strong>pas toutes les mêmes types ou nombres de paramètres</strong>. Néanmoins, <strong>le compilateur est capable de faire la différence</strong> et de ce fait, il laisse aux utilisateurs la <strong>possibilité de configurer le projet de différentes manières en fonction du <em><span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">type ou du nombre de données</span></span></em> renseigné.</strong></p>
<p>Prenons pour exemple la bibliothèque <strong>&lt;&lt;<span style="color: #ff6600;">LiquidCrystal</span>.h&gt;&gt; </strong>et observez ci-dessous les différences.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2490" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/19-Bibliotheque.png" alt="19 - Bibliotheque" width="546" height="242" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/19-Bibliotheque.png 546w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/19-Bibliotheque-300x133.png 300w" sizes="auto, (max-width: 546px) 100vw, 546px" /></p>
<p style="text-align: justify;">Nous avons<strong> quatre méthodes paramétrables toutes différentes</strong> l'une de l'autre. Ces dernières nous <strong>indiquent le type et le nombre de données à utiliser</strong> pour chaque paramètre. Les paramètres ont également été nommés? ce qui n'est pas toujours le cas.</p>
<p style="text-align: justify;">Mais à quoi sert le <strong><span style="color: #ff0000;">constructeur</span> </strong>?</p>
<p>Le <span style="color: #ff0000;">constructeur</span> <strong><span style="text-decoration: underline;">permet aux utilisateurs de renseigner et configurer un objet qui lui est rattaché</span> avec des données externes. </strong>Voyez l'exemple ci-dessous.<strong><br />
</strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-2493 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/20-Bibliotheque.png" alt="20 - Bibliotheque" width="499" height="67" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/20-Bibliotheque.png 387w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/20-Bibliotheque-300x40.png 300w" sizes="auto, (max-width: 499px) 100vw, 499px" /></p>
<p style="text-align: justify;">Ci-dessus <strong><span style="color: #ff6600;">LiquidCrystal</span> est notre classe</strong> puis nous avons<strong> créé un objet "lcd"</strong> et <strong>indiqué en paramètre</strong> le numéro des broches utilisées pour exploiter note afficheur LCD.</p>
<p style="text-align: justify;">Voici ce que cela donne à l'IDE avec la bibliothèque Servo.</p>
<p><img loading="lazy" decoding="async" class="wp-image-2513 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/22-Bibliotheque-e1490295069890.png" alt="22 - Bibliotheque" width="455" height="102" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/22-Bibliotheque-e1490295069890.png 308w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/22-Bibliotheque-e1490295069890-300x67.png 300w" sizes="auto, (max-width: 455px) 100vw, 455px" /></p>
<p style="text-align: justify;">On retrouve notre<strong> classe<span style="color: #ff6600;"> <span style="color: #000000;">"</span>Servo<span style="color: #000000;">"</span></span></strong><span style="color: #ff6600;"><span style="color: #000000;"> et notre <strong>objet "mon_servo"</strong>. Notamment, il n'y a <strong>pas de paramètres</strong> à renseigner car il n'a <strong>pas été déclaré pour cela.</strong> </span></span></p>
<p style="text-align: justify;">En déclarant notre objet, nous pouvons à présent depuis l'IDE faire appel à ce qui suit, c'est-à-dire les <strong>méthodes</strong>.</p>
<h5><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">3.2.2) Les méthodes.</span></strong></span></h5>
<p><img loading="lazy" decoding="async" class=" wp-image-2522 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23.1-Bibliotheque.png" alt="23.1 - Bibliotheque" width="371" height="256" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23.1-Bibliotheque.png 495w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/23.1-Bibliotheque-300x207.png 300w" sizes="auto, (max-width: 371px) 100vw, 371px" /></p>
<p style="text-align: justify;"><span style="color: #0000ff;"><span style="color: #000000;"><strong>Les méthodes</strong> <strong>sont en réalité des <span style="text-decoration: underline;"><em><span style="color: #ff0000; text-decoration: underline;">fonctions</span></em></span></strong> <strong>nommées méthodes pour les identifier comme appartenant à une bibliothèque</strong> et les différencier des <strong><span style="text-decoration: underline;"><em><span style="color: #ff0000; text-decoration: underline;">fonctions</span></em></span></strong> classiques que l'on peut créer dans nos programmes. Elles aussi peuvent être paramétrées ou non. </span></span>A cette étape du programme, nous avons la<strong> déclaration des <span style="color: #0000ff;">méthodes</span>. Un <span style="text-decoration: underline;"><em><span style="color: #ff0000; text-decoration: underline;">type</span> </em></span>et un <em><span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">nom</span> <span style="color: #ff0000; text-decoration: underline;">symbolique</span></span></em> sont attribués à la méthode et à ses paramètres.</strong> Exactement comme on le ferait pour une fonction.</p>
<p><strong><span style="color: #00ccff;">type </span>nomSymbolique (<span style="color: #00ccff;">type </span>nomSymbolique </strong><strong>) ;<br />
</strong></p>
<p><strong><span style="color: #00ccff;">uint8_t</span> attach (<span style="color: #008000;"><span style="color: #00ccff;">int</span> </span><span style="color: #008000;"><span style="color: #000000;">pin</span></span>); // attache la broche donnée au canal libre suivant, définit pinMode, renvoie le numéro de canal ou 0 si défaut.</strong></p>
<p style="text-align: justify;">Notez l'<strong>absence des accolades et des instructions</strong> aux méthodes. En effet, comme nous l'avons dit plus haut <strong>le fichier ".h" s'occupe principalement de la déclaration</strong>.<strong> La partie "exécutive" étant exécutée dans le fichier source ".cpp". </strong>Dans notre exemple (ci-dessus encadré en bleu), nous avons là toutes les méthodes utiles pour exploiter un servomoteur.<strong><br />
</strong></p>
<p style="text-align: justify;">Finalement, pour toutes bibliothèques <strong>si vous cherchez les méthodes</strong>, dont vous avez besoin, <strong>c'est à cet endroit que vous les trouverez</strong>. Certes, il ne vous est pas nécessaire de connaître leur programmation mais seulement leur utilité.</p>
<h5><strong><span style="text-decoration: underline; color: #0000ff;">Les exemples.</span></strong></h5>
<p style="text-align: justify;">Dans la plupart des bibliothèques <strong>les méthodes sont expliquées avec des commentaires.</strong> Mais dans certain cas, cela n'est pas fait. Heureusement dans ces cas là,<strong> les éditeurs intègrent toujours des exemples d'exploitation à leurs bibliothèques.</strong> A travers les exemples, vous trouverez les commentaires sur l'utilisation de chaque méthode.<strong><br />
</strong></p>
<p style="text-align: justify;">C'est pourquoi vous trouverez dans le dossier de chaque bibliothèque, <strong>un dossier nommé "examples</strong>". Toutefois, il n'est pas utile de passer par le dossier mais de simplement <strong>lancer l'exemple depuis l'IDE </strong>en cliquant sur<strong> "Fichier" </strong>ensuite sélectionnez<strong> "Exemple" </strong>puis le <strong>nom de la bibliothèque</strong> que l'on souhaite exploiter.</p>
<h5><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">Les mises en forme</span></strong></span></h5>
<p style="text-align: justify;">Cela à titre d'information. Quand vous utilisez une bibliothèque, <strong>la <span style="color: #ff6600;">classe</span> et les <span style="color: #ff6600;">méthodes </span>s'affichent à l'IDE en orange. </strong>C'est fait pour signaler leur utilisation dans un fichier de bibliothèque et vous assurer que vous l'avez bien orthographié. Aussi de cette façon, si vous déclarez, par hasard, <strong>une variable qui porte le même nom qu'une méthode utilisée dans l'une des bibliothèque incluse à votre programme;</strong> cette variable changera de couleur vous indiquant par conséquent qu'elle ne peut pas être utilisée comme telle.</p>
<p style="text-align: justify;">Ce jeu de couleur est appliqué dans un fichier nommé "<strong>Keywords</strong>.<strong>txt</strong>".</p>
<p style="text-align: justify;">Voici ce qu'il contient:</p>
<p><img loading="lazy" decoding="async" class=" wp-image-2525 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/25-Bibliotheque-1.png" alt="25 - Bibliotheque" width="242" height="271" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/25-Bibliotheque-1.png 378w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/25-Bibliotheque-1-267x300.png 267w" sizes="auto, (max-width: 242px) 100vw, 242px" /></p>
<p style="text-align: justify;">En fait, ici sont regroupés des mots-clés en<strong> deux catégories de format de couleurs</strong>. Le premier "KEYWORD1" et le second "KEYWORD2". Évidemment, les mots-clés <strong>choisis sont ceux utilisés pour les méthodes de la classe Servo.</strong></p>
<ul style="text-align: justify;">
<li>KEYWORD1 applique un c<strong>aractère gras et la couleur orange</strong>  aux mots-clés.</li>
<li>KEYWORD2 applique <strong>seulement la couleur orange</strong> aux mots-clés.</li>
</ul>
<p style="text-align: justify;">Il vous sera utile de connaître ce fichier le jour où vous créerez vous-même vos bibliothèques. Ce qui sera un sujet bientôt abordé.</p>
<p style="text-align: justify;">Vous savez à présent<strong> comment explorer le fichier "H" et comment identifier les méthodes utiles pour l'exploitation d'une bibliothèque</strong>. Amusez-vous à explorer les autres bibliothèques pour en comprendre le fonctionnement.</p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">MERCI.</span></strong></h3>
<h3 style="text-align: center;"><em><span style="text-decoration: underline;"><a href="https://plaisirarduino.fr/tutoriel/">PlaisirArduino/tutoriel.</a></span></em></h3>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">FIN.</span></strong></h3>
<p>&nbsp;</p>
<p>Cet article <a href="https://plaisirarduino.fr/explorer-une-bibliotheque/">Bibliothèque, comment l&rsquo;explorer ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>L&#8217;afficheur LCD. Qu&#8217;est ce que c&#8217;est ?</title>
		<link>https://plaisirarduino.fr/afficheur-lcd-comment-lexploiter/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Tue, 18 Apr 2017 18:08:38 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=2260</guid>

					<description><![CDATA[<p>l'afficheur LCD. Tout d’abord que veut dire LCD ? LCD est l'abréviation du terme anglais "Liquid Crystal Display" qui signifie en français  "Écran à cristaux liquides". D’où afficheur LCD. L'afficheur LCD est en particulier une interface visuelle entre un système (projet) et l'homme (utilisateur). Son rôle est de transmettre les &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/afficheur-lcd-comment-lexploiter/">L&rsquo;afficheur LCD. Qu&rsquo;est ce que c&rsquo;est ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">l'afficheur LCD.</span></span></strong></h1>
<p style="text-align: justify;">Tout d’abord<span class="_Tgc"><strong><span style="text-decoration: underline;"> que veut dire LCD</span> ?</strong></span> LCD est l'abréviation du terme anglais "<em><strong>L</strong>iquid <strong>C</strong>rystal<strong> D</strong>isplay</em>" qui signifie en français  "<strong>Écran à cristaux liquides</strong>". D’où afficheur <strong>LCD</strong>.</p>
<p style="text-align: justify;">L'afficheur LCD est en particulier une <strong>interface visuelle entre un système</strong> (projet)<strong> et l'homme </strong>(utilisateur). Son rôle est de transmettre les informations utiles d'un système à un utilisateur. Il<strong> affichera donc des données</strong> susceptibles d'être exploiter par l'utilisateur d'un système.</p>
<p><figure id="attachment_2266" aria-describedby="caption-attachment-2266" style="width: 1054px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-2266 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min.png" alt="Vue de face d'un afficheur LCD." width="1054" height="468" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min.png 1054w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min-300x133.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min-768x341.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min-1024x455.png 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-min-700x311.png 700w" sizes="auto, (max-width: 1054px) 100vw, 1054px" /><figcaption id="caption-attachment-2266" class="wp-caption-text">1602A (v2.0)</figcaption></figure></p>
<p>Nous utiliserons le modèle 1602A (V2.0) que l'on trouve dans le kit Arduino (2012).</p>
<h3><strong><span style="text-decoration: underline; color: #3366ff;">Comprendre l'afficheur</span><span style="text-decoration: underline;"><br />
</span></strong></h3>
<p style="text-align: justify;">Pour commencer nous détaillerons le <span style="text-decoration: underline;"><strong><span style="color: #00ccff;"><em><a style="color: #00ccff; text-decoration: underline;" href="https://www.openhacks.com/uploadsproductos/eone-1602a1.pdf">datasheet  de l 'afficheur 1602A (V2.0)</a>.</em></span></strong></span> C' est un document fourni par le constructeur dans lequel est<strong> détaillé ses caractéristiques, son fonctionnement et ses différentes utilisations possibles</strong>. Il est une <strong>source de renseignements très utile pour la maîtrise de son exploitation</strong>. Les datasheet sont, pour la plupart, en anglais.<strong> Aidez vous de <span style="text-decoration: underline; color: #00ccff;"><em>Google traduction</em></span> pour les traduire.</strong></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">1 - Les caractéristiques.</span></strong></h4>
<p style="text-align: justify;"><strong>La première information</strong> à connaître<strong> est le nombre de caractère affichable par ligne</strong>. Pour ce modèle, c'est 16 caractères sur deux lignes soit au total 32 caractères. De toute évidence, on retrouve cette information <strong>dans le datasheet sous la forme 16 X 02.</strong> Mais aussi dans la référence <strong><span style="color: #800080;">16</span>02</strong> A.</p>
<p style="text-align: justify;">On recueille également l'information du mode de <strong> transmission de données</strong> sur <strong>quatre (4) ou huit (8) bits</strong>.</p>
<p><figure id="attachment_2272" aria-describedby="caption-attachment-2272" style="width: 320px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2272" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/02-LCD.png" alt="Caractéristiques globales de l’afficheur LCD." width="320" height="179" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/02-LCD.png 427w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/02-LCD-300x168.png 300w" sizes="auto, (max-width: 320px) 100vw, 320px" /><figcaption id="caption-attachment-2272" class="wp-caption-text"><strong>Caractéristiques globales de l’afficheur LCD.</strong></figcaption></figure></p>
<p>En outre, <strong>les informations suivantes à connaître </strong>sont<strong> les tensions d'exploitations, caractéristiques électriques et mécaniques de l'afficheur LCD.</strong></p>
<p><figure id="attachment_2271" aria-describedby="caption-attachment-2271" style="width: 485px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2271" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/01-LCD-e1482099809744.png" alt="Tableau des tensions d'exploitations, caractéristiques électriques et mécaniques" width="485" height="388" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/01-LCD-e1482099809744.png 802w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/01-LCD-e1482099809744-300x240.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/01-LCD-e1482099809744-768x615.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/01-LCD-e1482099809744-700x560.png 700w" sizes="auto, (max-width: 485px) 100vw, 485px" /><figcaption id="caption-attachment-2271" class="wp-caption-text"><strong>Tableau des tensions d'exploitations, caractéristiques électriques et mécaniques</strong></figcaption></figure></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">2 - Le brochage.</span></strong></h4>
<p style="text-align: justify;">Le tableau ci-dessous représente bien le <strong>rôle de chaque broche et définit le brochage de l'afficheur LCD .</strong></p>
<p><figure id="attachment_2279" aria-describedby="caption-attachment-2279" style="width: 760px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-2279 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/03-LCD-1.png" alt="Tableau descriptif des fonctions de broches." width="760" height="428" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/03-LCD-1.png 760w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/03-LCD-1-300x169.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/03-LCD-1-700x393.png 700w" sizes="auto, (max-width: 760px) 100vw, 760px" /><figcaption id="caption-attachment-2279" class="wp-caption-text"><strong>Tableau descriptif du brochage.</strong></figcaption></figure></p>
<ul>
<li style="text-align: justify;">Premièrement, les<strong><span style="color: #008000;"> broches 1, 2 et 3</span></strong> sont dédiées à <strong><span style="color: #008000;">l'alimentation</span></strong>. La <strong>broche 1 et 2</strong> pour<strong> l'alimentation générale</strong>. La <strong>broche 3</strong> pour le branchement d'un potentiomètre qui <strong>contrôle le contraste de l'afficheur</strong>.</li>
<li style="text-align: justify;">Deuxièmement, les <strong><span style="color: #ff0000;">broches 4, 5 et 6</span></strong> pour le <strong><span style="color: #ff0000;">pilotage de la</span></strong> <strong><span style="color: #ff0000;">transmission des données</span></strong>. Elles pilotent l'écriture ou la lecture de données.</li>
<li style="text-align: justify;">Troisièmement, les <strong><span style="color: #ffff00;">broches de 7 à 14</span></strong>  pour le <strong><span style="color: #ffff00;">transfert des données elles-mêmes.</span></strong></li>
<li style="text-align: justify;">Et pour finir, les <strong><span style="color: #800080;">broches 15 et 16</span></strong> pour <strong><span style="color: #800080;">l'alimentation du rétro-éclairage</span></strong>.</li>
</ul>
<p style="text-align: justify;">Grâce à ces informations <strong>nous connaissons le brochage de l'afficheur</strong>. De plus nous avons en appui <strong>un schéma de raccordement.</strong></p>
<p><figure id="attachment_2290" aria-describedby="caption-attachment-2290" style="width: 456px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2290 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/04-LCD-schéma-e1482184623177.png" alt="04-lcd-schema" width="456" height="367" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/04-LCD-schéma-e1482184623177.png 456w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/04-LCD-schéma-e1482184623177-300x241.png 300w" sizes="auto, (max-width: 456px) 100vw, 456px" /><figcaption id="caption-attachment-2290" class="wp-caption-text">Schéma de câblage.<strong><span style="color: #ff0000;"> !! Ne pas câbler le fil rouge !!</span></strong>.</figcaption></figure></p>
<p style="text-align: justify;">Ce schéma illustre bien <strong>les branchements de l'alimentation principale et de ces auxiliaires.</strong> Nous avons ajouté<strong> le repérage des broches</strong>. Il y a une erreur signalée en rouge. <span style="text-decoration: underline;"><strong><span style="color: #ff0000; text-decoration: underline;">Ne pas câbler ce fil</span><span style="color: #ff0000; text-decoration: underline;">.</span></strong></span></p>
<p style="text-align: justify;">Nous avons donc maintenant <strong>suffisamment d'informations pour brancher l'afficheur LCD en toute confiance.</strong></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">3 - Les branchements de l'afficheur LCD.</span></strong></h4>
<p><figure id="attachment_2381" aria-describedby="caption-attachment-2381" style="width: 889px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2381 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/Afficheur-LCD.jpg" alt="Afficheur LCD" width="889" height="731" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/Afficheur-LCD.jpg 889w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/Afficheur-LCD-300x247.jpg 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/Afficheur-LCD-768x632.jpg 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/Afficheur-LCD-700x576.jpg 700w" sizes="auto, (max-width: 889px) 100vw, 889px" /><figcaption id="caption-attachment-2381" class="wp-caption-text">Schéma des branchements.</figcaption></figure></p>
<p>A présent que tout est en place. Comment l'activer et le piloter? De toute évidence? il nous faudra lui envoyer des données . <strong>Mais quelles données envoyer et comment ?</strong><strong><br />
</strong></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">4 - La transmissions de données.</span></strong></h4>
<p style="text-align: justify;">Observez le schéma ci-dessous. Nous avons ajouté<strong> le brochage</strong> suivant les repères du tableau. De plus, vous constaterez bien-sûr, la représentation de <strong>deux "modules"</strong>. Le<strong> <span style="color: #0000ff;">ST7066U</span></strong> et le <strong><span style="color: #339966;">ST7065C<span style="color: #000000;">.</span></span></strong></p>
<p><figure id="attachment_2292" aria-describedby="caption-attachment-2292" style="width: 707px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2292" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/05-LCD-schéma-transmission.png" alt="Schéma de transmission des données." width="707" height="291" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/05-LCD-schéma-transmission.png 703w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/05-LCD-schéma-transmission-300x124.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/05-LCD-schéma-transmission-700x289.png 700w" sizes="auto, (max-width: 707px) 100vw, 707px" /><figcaption id="caption-attachment-2292" class="wp-caption-text"><strong>Schéma de transmission des données.</strong></figcaption></figure></p>
<p style="text-align: justify;">Le ST7066U et le ST7065C sont <strong>des puces électronique utilisées en particulier pour piloter des matrices d'afficheurs LCD et</strong> <strong>capables de</strong> <strong>piloter 40 segments respectivement</strong>. Comme, par exemple, un<strong><span style="color: #00ccff;"><em><span style="text-decoration: underline;"><a style="color: #00ccff; text-decoration: underline;" href="https://plaisirarduino.fr/max-7219/"> MAX7219 avec une matrice à LED 8X8</a></span></em></span>.</strong></p>
<p><figure id="attachment_2304" aria-describedby="caption-attachment-2304" style="width: 360px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2304" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min.jpg" alt="Image arrière de l'afficheur." width="360" height="240" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min.jpg 3888w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min-300x200.jpg 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min-768x512.jpg 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min-1024x683.jpg 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/LCD-Arriere-min-700x467.jpg 700w" sizes="auto, (max-width: 360px) 100vw, 360px" /><figcaption id="caption-attachment-2304" class="wp-caption-text"><strong>Localisation des deux puces</strong></figcaption></figure></p>
<p><img loading="lazy" decoding="async" class="alignright wp-image-2297" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06-LCD-Matrice.png" alt="Représentation d'une matrice de caractères LCD" width="55" height="86" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06-LCD-Matrice.png 289w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06-LCD-Matrice-192x300.png 192w" sizes="auto, (max-width: 55px) 100vw, 55px" /></p>
<p style="text-align: justify;">En effet <strong>l'afficheur est composé de plusieurs matrices </strong>chacune d'elle indépendante. Ci-contre la représentation d'une matrice affichant le caractère "A".</p>
<p style="text-align: justify;">En définitive, il y<strong> a 32 matrices de cinq points sur huit (5X8) disposés sur deux lignes</strong> qui composent l'afficheur représenté ci-dessous.</p>
<p><figure id="attachment_2334" aria-describedby="caption-attachment-2334" style="width: 2897px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-2334 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1.png" alt="Affichage des matrices 5X8." width="2897" height="1069" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1.png 2897w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1-300x111.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1-768x283.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1-1024x378.png 1024w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/08-LCD-Matrice-afficheur-complet-1-700x258.png 700w" sizes="auto, (max-width: 2897px) 100vw, 2897px" /><figcaption id="caption-attachment-2334" class="wp-caption-text"><strong>Affichage des matrices 5X8.</strong></figcaption></figure></p>
<p style="text-align: justify;">En fait, <strong>les pilotes reçoivent les données,</strong> les interprètent et <strong>affichent les caractères</strong> voulus aux positions souhaitées. Mais pour cela, il faut leur <strong>transmettre des données.</strong></p>
<p style="text-align: justify;">D'ailleurs, les deux<strong> logigrammes de transmission</strong> de données ci-dessous. L'un <strong> Writing data</strong> pour la<strong> réception</strong> <strong>de données </strong> et l'autre <strong>Reading data</strong> pour la<strong> transmission de données. </strong>Cependant, la seule <strong>chose qui diffère</strong> entre ces deux diagrammes, c'est<strong> l'état à la broche "RW" en rouge</strong>.<strong><br />
</strong></p>
<p><figure id="attachment_2319" aria-describedby="caption-attachment-2319" style="width: 807px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-2319 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-réception-1-1.png" alt="Diagramme de réception de données." width="807" height="515" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-réception-1-1.png 807w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-réception-1-1-300x191.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-réception-1-1-768x490.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-réception-1-1-700x447.png 700w" sizes="auto, (max-width: 807px) 100vw, 807px" /><figcaption id="caption-attachment-2319" class="wp-caption-text"><strong>Diagramme de réception de données.</strong></figcaption></figure></p>
<p><figure id="attachment_2318" aria-describedby="caption-attachment-2318" style="width: 844px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="wp-image-2318 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-emission-1-1.png" alt="Diagramme d'émission de données." width="844" height="462" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-emission-1-1.png 844w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-emission-1-1-300x164.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-emission-1-1-768x420.png 768w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/07-LCD-Digramme-transmission-emission-1-1-700x383.png 700w" sizes="auto, (max-width: 844px) 100vw, 844px" /><figcaption id="caption-attachment-2318" class="wp-caption-text"><strong>Diagramme d'émission de données.</strong></figcaption></figure></p>
<p style="text-align: justify;">Ainsi, on comprend qu'<strong>en fonction de l'état "Haut" ou "Bas" à la broche "RW",</strong> le pilote de la matrice ST7066U est en<strong> mode de réception ou émission de données</strong>.</p>
<p style="text-align: justify;">Il n'y aura<strong> pas d'émission de données,</strong> la broche <strong>R/W</strong> sera donc par défaut <strong>à l'état bas "LOW" et par conséquent branché au 0V. </strong><strong><br />
</strong></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">5-Les instructions de données.</span></strong></h4>
<p style="text-align: justify;"><strong>Comment transmettre des données à l'afficheur LCD?</strong></p>
<p style="text-align: justify;">Le tableau ci-dessous regroupe <strong>les diverses instructions</strong> de pilotage de l'afficheur.</p>
<h1 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;"><img loading="lazy" decoding="async" class="alignnone wp-image-2322" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/09-LCD-Tableau-des-instructions.png" alt="09-lcd-tableau-des-instructions" width="605" height="752" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/09-LCD-Tableau-des-instructions.png 515w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/09-LCD-Tableau-des-instructions-241x300.png 241w" sizes="auto, (max-width: 605px) 100vw, 605px" /></span></span></strong></h1>
<p style="text-align: justify;">D'autan plus qu'à la suite du tableau,<strong> il y a un descriptif de ces instructions.</strong></p>
<p style="text-align: justify;">Donc pour ceux qui veulent plus de détails, à titre d'information<strong><a href="https://plaisirarduino.fr/telechargement/"> téléchargez la traduction</a></strong>, en français, du datasheet. Il faut reconnaître que malgré les termes non définis, cela vous sera <strong>plus facile de comprendre </strong>toutes les<strong> données utiles pour piloter l'afficheur LCD.</strong></p>
<p style="text-align: justify;">Pour transmettre ces données, <strong>il faut maîtriser le protocole de transmission de données</strong> entre l'Arduino et l'afficheur LCD. Créer une fonction de transfert de données et <strong>pour le moment, c'est hors de notre portée. </strong>Pour ces raisons, et heureusement pour nous,<strong> des programmeurs</strong> <strong>ont conçu ces fonctions</strong>. Nous n'avons donc plus qu'à les exploiter pour mettre en service l'afficheur.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;"><strong>Note:</strong></span> dans le jargon de programmeur les fonctions dont on parle sont normalement appelées <strong>des </strong><span style="color: #ff0000;">méthodes</span> .</p>
<h4><span style="text-decoration: underline;"><strong><span style="color: #3366ff; text-decoration: underline;">6-Les fonctions de la bibliothèque.</span><br />
</strong></span></h4>
<p style="text-align: justify;">Des programmeurs ont créé des <span style="color: #ff0000;">méthodes</span><strong> qui nous permettent d'exploiter l'afficheur.</strong> D'ailleurs, par simplicité et plus de flexibilité, ils les ont installé dans une <span style="color: #0000ff;">bibliothèque<span style="color: #000000;"> appelée</span></span> <strong>&lt;</strong><span style="color: #ff6600;">LiquidCristal</span>.h&gt;.</p>
<p style="text-align: justify;"><span style="color: #0000ff;"><span style="color: #000000;">Ces <span style="color: #ff0000;">méthodes,</span> n</span></span>ous les avons bien évidemment <span style="text-decoration: underline;"><strong> extraites en explorant le fichier d'en-tête</strong></span> de la bibliothèque <strong>&lt;<span style="color: #ff6600;">LiquidCristal</span>.h&gt;.</strong> <em>Vous trouverez comment le faire au travers du tutoriel intitulé <span style="color: #0000ff;"> &lt;&lt;Explorer une bibliothèque et découvrir ses méthodes&gt;&gt;</span>. </em></p>
<p style="text-align: justify;">Ci-dessous un tableau des <em><span style="color: #0000ff;">méthodes</span></em> de <strong>&lt;<span style="color: #ff6600;">LiquidCristal</span>.h&gt;</strong></p>
<p style="text-align: justify;">
<table id="tablepress-4" class="tablepress tablepress-id-4">
<thead>
<tr class="row-1">
	<th class="column-1">Nom de fonction.</th><th class="column-2">Rôles.</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">void clear();</td><td class="column-2">Efface l'afficheur.</td>
</tr>
<tr class="row-3">
	<td class="column-1">void home();</td><td class="column-2">Retourne le curseur au point d'origine (0,0).</td>
</tr>
<tr class="row-4">
	<td class="column-1">void noDisplay();</td><td class="column-2">Désactive l'affichage.<br />
</td>
</tr>
<tr class="row-5">
	<td class="column-1">void display();</td><td class="column-2">Active l'affichage.</td>
</tr>
<tr class="row-6">
	<td class="column-1">void noBlink();</td><td class="column-2">Désactive le clignotement du curseur.</td>
</tr>
<tr class="row-7">
	<td class="column-1">void blink();</td><td class="column-2">Active le clignotement du curseur.</td>
</tr>
<tr class="row-8">
	<td class="column-1">void noCursor();</td><td class="column-2">Désactive le curseur.</td>
</tr>
<tr class="row-9">
	<td class="column-1">void cursor();</td><td class="column-2">Active le curseur.</td>
</tr>
<tr class="row-10">
	<td class="column-1">void scrollDisplayLeft</td><td class="column-2">Décale l'affichage vers la gauche.</td>
</tr>
<tr class="row-11">
	<td class="column-1">void scrollDisplayRight();</td><td class="column-2">Décale l'affichage vers la droite.</td>
</tr>
<tr class="row-12">
	<td class="column-1">void leftToRight();</td><td class="column-2">Déplace le curseur vers la droite à l'affichage d'une donnée.</td>
</tr>
<tr class="row-13">
	<td class="column-1">void rightToLeft();</td><td class="column-2">Déplace le curseur vers la gauche à l'affichage d'une donnée.</td>
</tr>
<tr class="row-14">
	<td class="column-1">void autoscroll();</td><td class="column-2">Active le défilement automatique de l'affichage vers la gauche.</td>
</tr>
<tr class="row-15">
	<td class="column-1">void noAutoscroll();</td><td class="column-2">Désactive le défilement automatique de l'affichage vers la gauche.</td>
</tr>
<tr class="row-16">
	<td class="column-1">void createChar(uint8_t, uint8_t[]);</td><td class="column-2">Permet l'appel de caractères ou symboles pré- construit dans un tableau.</td>
</tr>
<tr class="row-17">
	<td class="column-1">void setCursor(uint8_t, uint8_t); </td><td class="column-2">Place le curseur à la position souhaitée.</td>
</tr>
<tr class="row-18">
	<td class="column-1">void setRowOffsets(int row1, int row2, int row3, int row4)<br />
</td><td class="column-2">?</td>
</tr>
<tr class="row-19">
	<td class="column-1">virtual size_t write(uint8_t);</td><td class="column-2">?</td>
</tr>
<tr class="row-20">
	<td class="column-1">void command(uint8_t);<br />
</td><td class="column-2">?</td>
</tr>
</tbody>
</table>
</p>
<p style="text-align: justify;">Pour <strong>utiliser les <em><span style="color: #0000ff;">méthodes</span></em> d'une bibliothèque,</strong> il faut avant toute chose <a href="https://plaisirarduino.fr/bibliotheque/">l'inclure dans le progra</a><a href="https://plaisirarduino.fr/bibliotheque/">mme</a><a href="https://plaisirarduino.fr/bibliotheque/"> </a> par l'instruction <strong><span style="color: #808000;">#include</span><span style="color: #99cc00;"> </span>&lt;<span style="color: #ff9900;">bibliothèque</span>.h&gt;</strong> .</p>
<p><img loading="lazy" decoding="async" class="wp-image-2391 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-LCD-include.png" alt="10-LCD include" width="466" height="50" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-LCD-include.png 270w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/10-LCD-include-268x29.png 268w" sizes="auto, (max-width: 466px) 100vw, 466px" /></p>
<p style="text-align: justify;">Une fois incluses, nous pouvons commencer la programmation.</p>
<p style="text-align: justify;">Mais avant de commencer,  il va<strong> falloir initialiser et configurer l'afficheur</strong>. Sans cela impossible d'utiliser les <em><span style="color: #0000ff;">méthodes</span></em> .</p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">7-Initialisation, configuration et test de l'afficheur LCD.</span></strong></h4>
<h5 style="text-align: justify;"><strong>L'initialisation.</strong></h5>
<p style="text-align: justify;">Premièrement, il faut donc<strong> initialiser l'Arduino en fonction des besoins de l'afficheur</strong>. Cela consiste à <strong>attribuer aux broches de l’Arduino des tâches de travail en fonction des broches de l'afficheur.</strong></p>
<p style="text-align: justify;">Étant donné que c'est une initialisation, elle<strong> s'effectue en tête de programme</strong> par l'<strong>appel de la classe</strong> <strong><span style="color: #ff6600;">LiquidCrystal</span></strong> et <strong>en lui attribuant un</strong> <strong><span style="text-decoration: underline;">OBJET.</span> </strong>On dit ici faire une instanciation. Comme illustré ci-dessous "<strong>lcd</strong>" est <strong>l'objet</strong>. (<em>Vous pouvez lui donner le nom de votre choix.)</em></p>
<p><img loading="lazy" decoding="async" class="wp-image-2418 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-LCD-initialisation.png" alt="13-LCD initialisation" width="509" height="92" /></p>
<p style="text-align: justify;">Néanmoins, vous constaterez que <strong>l'attribution d'un objet ne suffit pas.</strong> Il faut <strong>également attribuer des données préalablement déclarées</strong>. Ces données consistent à<strong> initialiser les broches</strong>. <em>(Vous pouvez aussi bien ne pas les déclarer et utiliser le numéro de broche).</em></p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Il faut souligner que<strong> l'ordre de chaque donnée a son utilité et son importance</strong>. Elles correspondent particulièrement à un traitement bien défini car elles seront traitées pour exécuter une tâche bien précise.</span></p>
<ul>
<li style="text-align: justify;"><strong>RS : </strong>Donnée de broches qui synchronise les données.</li>
<li style="text-align: justify;"><strong>E : </strong>Donnée de broches qui active la réception des données.</li>
<li style="text-align: justify;"><strong>D4, D5, D6, Et D7 ; </strong>Données de broches qui transmettent les données.</li>
</ul>
<p style="text-align: justify;">Ci-dessous un exemple de déclaration des broches en fonction de notre exemple.</p>
<p><img loading="lazy" decoding="async" class="wp-image-2420 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-LCD-Declaration..png" alt="14-LCD Declaration." width="462" height="152" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-LCD-Declaration..png 365w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/14-LCD-Declaration.-300x99.png 300w" sizes="auto, (max-width: 462px) 100vw, 462px" /></p>
<p style="text-align: justify;">Nous sommes en<strong> mode transmission de données quatre bits, délivrée en quartet, soit quatre bits</strong> <strong>via les broches 2,3,4 et 5</strong>.<strong> Les broches 12 et 11 pilotent le transfert des données.</strong> Nous pourrions utiliser huit bits (plus rapide) mais quatre bits (plus simple) suffiront largement.</p>
<h5><strong>La configuration.</strong></h5>
<p style="text-align: justify;">Une fois initialisée,  il faut<strong> configurer le LCD</strong> dans le <strong><span style="color: #99cc00;">setup<span style="color: #000000;">() </span></span></strong><span style="color: #99cc00;"><span style="color: #000000;">grâce à la <em><span style="color: #0000ff;">méthode</span></em> <strong><span style="color: #ff6600;">begin</span>()</strong> en rattachant son objet "<strong>lcd</strong>" et en la paramétrant.</span></span></p>
<p><img loading="lazy" decoding="async" class="wp-image-2387 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/03-LCD.jpg" alt="03-LCD" width="593" height="106" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/03-LCD.jpg 403w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/02/03-LCD-300x54.jpg 300w" sizes="auto, (max-width: 593px) 100vw, 593px" /></p>
<p style="text-align: justify;">Ci-dessus la première donnée (16) est le nombre de colonne et la seconde (2) le nombre de ligne. Nous pouvons à présent<strong> mettre en service l'afficheur pour le tester. </strong></p>
<h5><strong>Le test.</strong></h5>
<p style="text-align: justify;"><strong>Pour tester l'afficheur nous utiliserons donc la </strong><em><span style="color: #00ccff;"><a style="color: #00ccff;" href="https://plaisirarduino.fr/explorer-une-bibliotheque/">méthode</a></span></em><strong><span style="color: #ff6600;"> print</span>();</strong> que nous connaissons déjà. Comme illustré ci-dessous ne pas oublier de <strong>placer le message entre guillemets.</strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-2397 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/11-LCD-helloworld-Setup.png" alt="11-LCD helloworld Setup" width="470" height="54" /></p>
<p style="text-align: justify;">L'affichage du message confirmera alors le bon branchement et le fonctionnement de l'afficheur. Passons donc à l'étape de l'exploitation<strong>.</strong></p>
<h4><strong><span style="text-decoration: underline; color: #3366ff;">8-L'exploitation de l'afficheur.</span></strong></h4>
<p style="text-align: justify;">Ensuite pour exploiter l'afficheur LCD,  il suffit de<strong> faire appel aux autres <em><span style="color: #00ccff;"><a style="color: #00ccff;" href="https://plaisirarduino.fr/explorer-une-bibliotheque/">méthode</a></span></em> de la bibliothèque</strong>. V<strong>ous trouverez aussi des exemples de programmes fournis avec la bibliothèque</strong>.</p>
<p style="text-align: justify;"><strong>En effet, dans le menu de l'IDE</strong>. Via FICHIER =&gt; EXEMPLE =&gt; LiquidCrystal =&gt; tous les exemples d'exploitation possibles.</p>
<p><img loading="lazy" decoding="async" class="wp-image-2409 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-LCD-menu-exemple.jpg" alt="13-LCD menu exemple" width="408" height="476" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-LCD-menu-exemple.jpg 533w, https://plaisirarduino.fr/arduino/wp-content/uploads/2017/03/13-LCD-menu-exemple-257x300.jpg 257w" sizes="auto, (max-width: 408px) 100vw, 408px" /></p>
<p style="text-align: justify;">L'ensemble des <strong><em><span style="color: #00ccff;"><a style="color: #00ccff;" href="https://plaisirarduino.fr/explorer-une-bibliotheque/">méthodes</a></span></em> es</strong>t utilisé dans les exemples. Pour cette raison, nous ne détaillerons pas l'exploitation des <em><span style="color: #00ccff;"><a style="color: #00ccff;" href="https://plaisirarduino.fr/explorer-une-bibliotheque/">méthodes</a></span></em> car les exemples sont simples à comprendre. <em> Reportez-vous au tableau des <span style="color: #00ccff;"><a style="color: #00ccff;" href="https://plaisirarduino.fr/explorer-une-bibliotheque/">méthodes</a></span> plus haut dans  le chapitre six " Les fonctions de la bibliothèque".</em></p>
<p style="text-align: justify;">Vous savez à présent <strong>de quoi se compose un afficheur LCD</strong> <strong>et comment le mettre en service.</strong> Apprenez et amusez-vous à manipuler et modifier les exemples selon vos besoins de programmation de vos projets. <em>Aidez-vous des traducteurs pour les traduire.</em></p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">MERCI.</span></strong></h3>
<h3 style="text-align: center;"><em><span style="text-decoration: underline;"><strong><span style="color: #00ccff;"><a style="color: #00ccff; text-decoration: underline;" href="https://plaisirarduino.fr/tutoriel/">PlaisirArduino/tutoriel.</a></span></strong></span></em></h3>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">FIN.</span></strong></h3>
<p>Cet article <a href="https://plaisirarduino.fr/afficheur-lcd-comment-lexploiter/">L&rsquo;afficheur LCD. Qu&rsquo;est ce que c&rsquo;est ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Analogique et MLI. Gestion de ces signaux</title>
		<link>https://plaisirarduino.fr/signaux-dentrees-et-sortie-analogique/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Thu, 08 Dec 2016 21:08:38 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=1469</guid>

					<description><![CDATA[<p>Gestion d'un signal analogique et MLI Introduction Au travers de ce tutoriel, nous allons exploiter un signal analogique en entrée pour piloter en sortie PMW dit MLI en français Modulation de Largeur d'Impulsion. Le but est de faire varier la luminosité d'une LED en agissant sur un potentiomètre. Pour cela &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/signaux-dentrees-et-sortie-analogique/">Analogique et MLI. Gestion de ces signaux</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><span style="color: #0000ff;"><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">Gestion d'un signal analogique et MLI</span></strong><br />
</span></span></h1>
<h3 style="text-align: left;"><strong><span style="text-decoration: underline;"><span style="color: #000000; text-decoration: underline;">Introduction</span></span></strong></h3>
<p>Au travers de ce tutoriel, nous allons exploiter un <strong>signal analogique en entrée pour piloter en sortie PMW dit MLI</strong> en français <span style="text-decoration: underline;"><strong>M</strong></span>odulation de<span style="text-decoration: underline;"><strong> L</strong></span>argeur d'<span style="text-decoration: underline;"><strong>I</strong></span>mpulsion.</p>
<p>Le but est de <strong>faire varier la luminosité d'une LED</strong> <strong>en agissant sur un potentiomètre</strong>. Pour cela nous allons utiliser:<img loading="lazy" decoding="async" class="alignright" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/Potentiometre.png" alt="potentiometre" width="240" height="195" name="images1" align="BOTTOM" border="1" /></p>
<ul>
<li>Une carte Adruino UNO.</li>
<li>Un potentiomètre de 10Kohm.</li>
<li>Une résistance de charge de 220ohm.</li>
<li>Une LED de couleur rouge.</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/LED-Resisstance-e1473599736162.jpg" alt="LED et résistance" width="235" height="132" name="images2" align="BOTTOM" border="1" /></p>
<p>Pour comprendre la gestion <strong>PWM,</strong> il faut tout d’abord faire un petit rappel. Vous découvrirez plus de détail, en cliquant <strong><span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/les-entrees-sortie-de-la-platine-arduino/">ici</a>.</span></span></strong></p>
<h3 style="text-align: left;"><strong><span style="text-decoration: underline;">Les branchements.</span></strong></h3>
<p>Commençons par examiner <span style="font-family: Arial,sans-serif;"><span style="font-size: medium;">la platine Arduino UNO :</span></span></p>
<ul>
<li>Nous avons<strong> 12 broches configurables en <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/les-entrees-sortie-de-la-platine-arduino/">entrées ou sorties </a></span></span>repérées de 2 à 13</strong>. Seules les broches PMW repérées avec ce symbole "<strong>~"</strong> configurées en sorties modulerons une longueur d'impulsion numérique <strong>MLI</strong> calculée sur une <strong>résolution numérique de 8bits</strong> qui représente une plage de<strong> 0 à 255 points de mesure</strong>. Ce procédé simule un signal de sortie analogique mais qui en fait n'en n'est pas un. Donc nous utiliserons la broche 3, repéré par le sigle "~" (PMW).</li>
<li>Il y a également<strong> 6 broches d'entrées, repérées de A0 à A5</strong>, spécifiquement conçues pour le <strong>traitement des signaux de tensions analogiques</strong><span style="text-decoration: underline;"> allant jusqu'à 5V max.</span> Elles exploitent un <strong><span style="text-decoration: underline;">convertisseur analogique/numérique</span> d'une résolution numérique de 10 BITS</strong> qui représentent une plage <strong>de 0 à 1023 points de mesure</strong>. C'est pour cela que nous utiliserons l'une de ces broches pour raccorder notre potentiomètre, à l'occurrence A0.</li>
</ul>
<p style="text-align: center;"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/Signal-analogique-Schéma..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/Signal-analogique-Schéma..png" alt="signal-analogique-schema" width="641" height="407" name="images3" align="BOTTOM" border="1" /></span></a><strong><span style="color: #ff0000;">Ne surtout pas dépasser la tension de 5V max si celle-ci est externe à la carte Arduino.</span></strong></p>
<h2 style="text-align: center;"><span style="color: #000000;"><strong><span style="text-decoration: underline;">Le programme.</span></strong></span></h2>
<h3 style="text-align: center;" align="LEFT"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Déclarations.</span></span></strong></h3>
<p>En premier lieu, nous<span style="text-decoration: underline;"> <span style="color: #333399;"><strong>déclarons</strong></span><strong> nos variables.</strong></span></p>
<h3 style="text-align: center;"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/01-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/01-Signale-analogique..png" alt="01-signale-analogique" width="449" height="70" name="images4" align="BOTTOM" border="1" /></span></a><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Configurations.</span></span></strong></h3>
<p style="text-align: left;">Nous établissons ensuite nos <strong><span style="text-decoration: underline;">configurations</span>.</strong></p>
<ul>
<li>Pour un retour visuel des valeurs exploitées au moniteur série, nous paramétrons la <strong>Vitesse du port série.</strong></li>
<li>Nous <strong>configurons en mode sortie la broche utile</strong> au pilotage de la LED.</li>
</ul>
<p align="LEFT"><span style="text-decoration: underline;"><strong>NOTE</strong></span>: il faut souligner qu'il n'est <strong>pas nécessaire de configurer une broche d'entrée analogique</strong> quant elle est utilisée pour ce type de signal.</p>
<p align="LEFT"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/02-Signale-analogique.-e1473601389801.png"><span style="color: #000080;"><img loading="lazy" decoding="async" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/02-Signale-analogique.-e1473601389801.png" alt="02-signale-analogique" width="640" height="226" name="images5" align="BOTTOM" border="1" /></span></a></p>
<h3 style="text-align: center;" align="LEFT"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Test.</span></span></strong></h3>
<h6 align="LEFT"><em>Pour s'assurer que tout fonctionne correctement, il faut tester nos configurations et nos équipements Cela évite de chercher un bogue dans le  programme alors que c'est l'équipement qui est en cause.</em></h6>
<p>Premièrement nous <strong>testons la LED</strong>. Nous <strong>l'activons trois fois</strong> <strong>pour la contrôler visuellement</strong>.</p>
<p>Deuxièmement, pour contrôler le potentiomètre nous utilisons la fonctions <strong><span style="color: #ff6600;">analogRead</span> ();</strong> qui lit la valeur de tension à la broche sélectionnée et la<strong> convertit en chiffre entier de 0 à 1023, puis </strong>nous <strong>positionnons le potentiomètre en butée mini</strong> (gauche) <strong>ou maxi</strong> (droite)  et effectuons une<strong> lecture de notre signal à l'un de ces deux points</strong>.  On<strong> teste ensuite que la valeur lue correspond bien à 0 (mini) ou à 1023 (maxi)</strong> à l'un de ces deux points. Si ce n'est pas le cas, il y a un problème de branchements.</p>
<p><strong><span style="color: #ff6600;">analogRead</span>(Broche à lire);</strong>  //Ou variable affectée à la broche.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/03-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/03-Signale-analogique..png" alt="03-signale-analogique" width="739" height="578" name="images6" align="BOTTOM" border="1" /></span></a>Vous constaterez l'utilisation de<strong> <a href="https://plaisirarduino.fr/la-boucle-while/"><span style="text-decoration: underline;"><span style="color: #3366ff;">while(1)</span></span></a></strong> dans le test qui<strong> stoppera l'évolution du programme</strong>. En effet dans le cas ou un <strong>défaut de lecture</strong> est vrais lors du test il faudra donc <strong>relancer le programme par un re-set sur la platine ou un téléversement.</strong></p>
<p><strong>Note:</strong> Dans ce programme, nous n'avons pas d'initialisation à effectuer.</p>
<h2 style="text-align: center;"><span style="color: #000000;"><strong><span style="text-decoration: underline;">Programme principal.</span></strong></span></h2>
<p>Nous décomposons le programme principal en quatre parties.</p>
<ol>
<li>La déclaration des variables locales.</li>
<li>L'acquisition du signal.</li>
<li>Le traitement du signal.</li>
<li>L'exploitation du signal.</li>
</ol>
<h3 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Déclarations.</span></span></strong></h3>
<h3 style="text-align: center;"><span style="color: #0000ff;"><a style="color: #0000ff;" href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/04-Signale-analogique..png"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/04-Signale-analogique..png" alt="04-signale-analogique" width="635" height="70" name="images7" align="BOTTOM" border="1" /></a><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Acquisitions.</span></span></strong></span><strong><br />
</strong></h3>
<p>Ensuite, nous réalisons la <strong>lecture de la valeur</strong> du potentiomètre par la fonction <strong><span style="color: #ff6600;">analog</span><span style="color: #ff6600;">Read</span>();</strong> et <strong>chargeons la valeur</strong> acquise <strong>dans la variable de traitement</strong>  (V.T.)  "<strong>val</strong>_<strong>potar</strong>" .</p>
<h3 style="text-align: center;"><strong><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/05-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/05-Signale-analogique..png" alt="05-signale-analogique" width="711" height="141" name="images8" align="BOTTOM" border="1" /></span></a></strong><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">Traitement des signaux.</span></strong><br />
</span></h3>
<p>Une fois la valeur chargée, nous pouvons la manipuler. A cette étape nous allons convertir, mettre à l'échelle et limiter les signaux.</p>
<h5 style="text-align: left;"><strong><span style="text-decoration: underline;"><span style="color: #000000; text-decoration: underline;">Conversion</span></span></strong></h5>
<p>Tout d'abord, pour une exploitation plus parlante de notre projet au travers du moniteur série, il est <strong>utile de connaître la valeur de tension équivalente</strong> de la donnée brute. En d'autres termes, <strong>convertir la donnée brute en volt.</strong></p>
<ul>
<li>Donc nous allons <strong>diviser la tension de service aux bornes du potentiomètre par le nombre de points de lecture</strong>. Soit 5Volts divisés 1024 points. Ce qui nous donne un coefficient "K" de conversion que l'on applique par multiples à notre donnée brute. (48.82*10e-3). Après cela nous connaissons théoriquement la valeur de tension appliquée à l'entrée analogique.</li>
</ul>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.1-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.1-Signale-analogique..png" alt="06-1-signale-analogique" width="622" height="120" name="images9" align="BOTTOM" border="1" /></span></a><span style="text-decoration: underline;"><strong>Note:</strong></span> Par ailleurs, vous pouvez vous <strong>brancher en parallèle </strong>au signal de sortie du potentiomètre<strong> un appareil de mesure.</strong> Néanmoins, des écarts sont à noter et à corriger si nécessaire.</p>
<p><strong>La tension de service est la tension maximum qui sera appliquée à l'entrée analogique.</strong></p>
<h4><strong><span style="color: #ff0000;">Ne surtout pas dépasser la tension de 5V maxi si celle-ci est externe à la carte Arduino.</span></strong></h4>
<h5 style="text-align: left;"><strong><span style="text-decoration: underline;">Mise à l'échelle.</span></strong></h5>
<p>Ensuite, il va nous falloir <strong>réaliser une concordance entre le signal d'entrée et de sortie</strong>. Malgré cela, elles n’ont pas la même échelle de mesure car un signal <strong>PWM en sortie est de 255 points et que le signal analogique d'entrée est de 1024 points.</strong></p>
<ul>
<li>La fonction <strong><span style="color: #ff9900;">map<span style="color: #000000;">();</span></span></strong> nous aide à <strong>réaliser une mise à l'échelle du signal d'entrée avec le signal de sortie.</strong> De sorte que nous obtenons une corrélation entre le signal d'entrée et de sortie.</li>
</ul>
<p><strong><span style="color: #ff9900;">map</span> (VT* , mini VT, maxi VT, mini VS*, maxi VS);</strong> //Format de la fonction.</p>
<p><em> *VT = Variable de traitement *VS = Variable de Sortie.</em></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.2-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.2-Signale-analogique..png" alt="06-2-signale-analogique" width="707" height="107" name="images10" align="BOTTOM" border="1" /></span></a>Nous obtiendrons donc 255 points en sortie pour 1023 point en lecture d'entrée.</p>
<h5 style="text-align: left;"><strong>Limitation.</strong></h5>
<p>Certains projets ont des <strong>butées mécaniques de fonctionnement</strong> qu'il ne faut surtout pas atteindre par risque de casse ou blocage.  Par conséquent, il ne faut <strong>pas dépasser certaines valeurs de pilotage en sortie.</strong> C'est pour cela que nous utilisons la fonction  <strong><span style="color: #ff9900;">constrain</span>();</strong> qui nous aide à effectuer cette opération.</p>
<p>Toutefois, <strong><span style="color: #ff9900;">constrain</span></strong> de l'anglais veux dire <strong>LIMITER</strong>. Nous réalisons donc par cette fonction une mise en butée du pilotage électrique.</p>
<p><strong><span style="color: #ff9900;">constrain</span>(*VT, mini , maxi );</strong> // *VT Variable de traitement.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.3-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/06.3-Signale-analogique..png" alt="06-3-signale-analogique" width="729" height="135" name="images11" align="BOTTOM" border="1" /></span></a><strong>CONSEIL:</strong> Nous pouvons <strong>appliquer cette limitation à deux endroits</strong> du programme. Soit au signal d'entrée ou au signal de sortie. <strong>Il est sécurisant de le faire en sortie</strong> car <span style="text-decoration: underline;">une erreur de traitement (calcul) de la valeur du signal dans le programme  peut avoir des valeurs non acceptables pour vos projets.</span></p>
<p>Les valeurs de limitations du signal de sortie se détermine par des relevés ou des calculs effectués par vos soins et en connaissance du projet.</p>
<p>La mise en butée du signal d'entrée peut aussi être directement réalisé dans la fonction  <strong><span style="color: #ff9900;">map</span></strong>(); avec les paramètres de sorties mini et maxi.</p>
<h5 style="text-align: left;"><strong><span style="text-decoration: underline;"><span style="color: #000000; text-decoration: underline;">Conversion</span></span></strong></h5>
<p>Pour les même raison que le signal analogique d'entrée, il nous est utile de<strong> connaître la valeur en tension équivalente à la donnée brute d'exploitation</strong> en sortie. Nous opérons une conversion comme décrit plus haut mais avec une résolution de 255 points.</p>
<ul>
<li>Il faut également <strong>diviser la tension de service aux bornes du potentiomètre par le nombre de points de résolution de lecture</strong>. Soit 5 Volts divisés par 255 points. Cela nous donne un coefficient "K" de conversion que l'on applique par multiples à notre donnée brute de sortie. (195.3*10e-3).<br />
Grâce à cela nous connaissons théoriquement la valeur de tension appliquée à la sortie pour le  pilotage.</li>
</ul>
<p><img loading="lazy" decoding="async" class="wp-image-2235 size-full aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06.4-Signale-analogique.-e1480615630726.png" width="536" height="112" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06.4-Signale-analogique.-e1480615630726.png 536w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/12/06.4-Signale-analogique.-e1480615630726-300x63.png 300w" sizes="auto, (max-width: 536px) 100vw, 536px" /></p>
<p><strong><span style="text-decoration: underline;">L'exploitation</span></strong></p>
<p>Finalement, une fois le signal traité, nous l’intégrons à la fonction  <strong><span style="color: #ff9900;">analogWrite</span>();</strong> pour <strong>appliquer la consigne de pilotage.</strong></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/07-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/07-Signale-analogique..png" alt="07-signale-analogique" width="667" height="109" name="images13" align="BOTTOM" border="1" /></span></a>La LED s'allume en fonction de la valeur traitée.</p>
<p>En conclusion, nous constatons que la valeur de <strong>tension appliquée à la LED ne dépassera pas les 4,10V</strong>. Le signal de sortie étant mis en butée mini et maxi, la valeur de sortie n'atteindra jamais 0V et 5V. Nous voyons ci-dessous le résultat du traitement signal par le moniteur série.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/08-Signale-analogique..png"><span style="color: #000080;"><img loading="lazy" decoding="async" class="aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/08-Signale-analogique..png" alt="08-signale-analogique" width="428" height="143" name="images14" align="BOTTOM" border="1" /></span></a>Si l'on voulait, nous pourrions même <strong>limiter la tension de pilotage à 2V</strong> pour se passer de la résistance de charge de la LED.</p>
<p>Vous connaissez à présent les bases et quelques outils utiles pour l'exploitation d'un signal analogique en entrée et modulé en sortie.</p>
<p>Découvrez et exploitez le signal analogique en <a href="https://plaisirarduino.fr/telechargement/"><em><span style="color: #0000ff;">téléchargeant les sketchs</span> </em></a>référents de ce sujet.</p>
<p><em>++ Petit plus ce programme exemple n'est pas visuellement confortable pour une exploitation via le moniteur série. C'est pour cela que nous vous proposons aussi un programme évolué "Signale_analogique_EVO" de cet exemple qui n'affiche que la valeur actualisée lors d'un changement de valeur au potentiomètre. Vous le trouverez dans la rubrique téléchargement.++.</em></p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">MERCI</span></strong>.</h3>
<h3 style="text-align: center;"><a href="https://plaisirarduino.fr/tutoriel/"><em><span style="color: #0000ff;">PlaisirArduino/tutoriel.</span></em></a></h3>
<h3 style="text-align: center;"><strong><span style="text-decoration: underline; color: #0000ff;">FIN.</span></strong></h3>
<p>Cet article <a href="https://plaisirarduino.fr/signaux-dentrees-et-sortie-analogique/">Analogique et MLI. Gestion de ces signaux</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bibliothèque, comment l&#8217;installer ?</title>
		<link>https://plaisirarduino.fr/bibliotheque/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Mon, 14 Nov 2016 20:50:38 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=1647</guid>

					<description><![CDATA[<p>Installer une bibliothèque Description. Dans l'univers Arduino, vous rencontrerez les LIBRARIES , que l'on appelle bibliothèques . Certaines sont intégrées d'origine au sein du compilateur mais il est aussi possible d'en ajouter en les téléchargeant sur Internet. Mais en réalité, c'est un sous-programme qui forme un groupement de fonctions utiles à l'exploitation &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/bibliotheque/">Bibliothèque, comment l&rsquo;installer ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><strong><span style="text-decoration: underline; color: #0000ff;">Installer une bibliothèque </span></strong></h1>
<h3><span style="text-decoration: underline;">Description.</span></h3>
<p>Dans l'univers Arduino, vous rencontrerez les <strong><em>LIBRARIES</em></strong> , que l'on appelle <strong>bibliothèques </strong>. Certaines sont<strong> intégrées d'origine au sein du compilateur mais il est aussi possible d'en ajouter</strong> en les téléchargeant sur Internet.</p>
<p>Mais en réalité,<strong> c'est un sous-programme</strong> <strong>qui forme un groupement de fonctions</strong> utiles à <strong>l'exploitation d'équipements</strong> comme les <span style="text-decoration: underline;">servomoteurs</span>, les <span style="text-decoration: underline;">afficheurs LCD</span> ou gérer des<span style="text-decoration: underline;"> communications SPI</span> et autres <span style="text-decoration: underline;">composants électroniques</span><strong>.</strong></p>
<h2><span style="text-decoration: underline;">Charger une bibliothèque.</span></h2>
<p>Il vous sera parfois nécessaire d'installer une librairie qui ne fait pas partie de la liste. Tout d'abord, il vous faudra la télécharger sous format ZIP sur Internet.</p>
<p>Prenons l'exemple de <strong>&lt;<span style="color: #ff6600;">RTClib</span>.h&gt;</strong> utile à la gestion des temps horaires coordonnés pour avoir l'heure exacte. <strong>Après avoir recherché et trouvé un site ou télécharger la bibliothèque</strong>.</p>
<ol>
<li><strong>D’abord, téléchargez la en format ZIP</strong> dans un ficher de destination de votre choix. Nous prendrons "Téléchargement" par défaut.</li>
<li>Vous lancez ensuite votre compilateur et ouvrez le menu "<strong>croquis</strong>", sélectionner "<strong>inclure une bibliothèque</strong>". Puis la fenêtre déroulante s'ouvre. Cliquez sur " <strong>Ajoutez une bibliothèque ZIP</strong>".</li>
<li>L'explorateur de fichiers s'ouvre. <strong>Sélectionnez et ouvrez votre dossier de destination</strong> en l’occurrence pour nous "Téléchargement". <strong>Recherché le </strong><img loading="lazy" decoding="async" class="wp-image-1672 alignleft" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/03-Bibliotheque..png" alt="03-bibliotheque" width="87" height="126" /><strong>fichier ZIP appelé RTClib et cliquez dessus.</strong></li>
<li>Vous <strong>retournerez systématiquement au compilateur</strong> et constaterez la confirmation du chargement.</li>
</ol>
<p>&nbsp;</p>
<p><a href="https://plaisirarduino.fr/?attachment_id=1673"><img loading="lazy" decoding="async" class="aligncenter wp-image-1673" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/04-Bibliotheque..png" alt="04-bibliotheque" width="598" height="519" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/04-Bibliotheque..png 655w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/04-Bibliotheque.-300x261.png 300w" sizes="auto, (max-width: 598px) 100vw, 598px" /></a>Finalement, vous avez installé <strong>RTClib</strong>.<strong>h</strong> dans la librairie du compilateur.</p>
<p>Il ne vous reste plus qu'a l'installer dans vos programmes. A l'opposé des originales, celle-ci se trouve dans une seconde liste appelé "<strong>Contributed bibliothèque</strong>". Il y a aussi une autre liste "<strong>Recommended bibliothèque</strong>".</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1716" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/05-Bibliotheque..png" alt="05-bibliotheque" width="598" height="696" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/05-Bibliotheque..png 662w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/05-Bibliotheque.-258x300.png 258w" sizes="auto, (max-width: 598px) 100vw, 598px" /></p>
<p><strong>Note:</strong> Vous retrouverez aussi les fichiers source (.h) des bibliothèques dans le fichier d'installation "<strong>Arduino</strong>" dans programme files dans le fichier "<strong>libraries</strong>". Prenez garde à ne pas les modifier si vous ne maîtrisez pas la programmation car il serait endommagé et plus du tout utilisable.</p>
<h2><span style="text-decoration: underline;">Faire appel à une bibliothèque. </span></h2>
<p>Pour  faire appel à une bibliothèque, il faut aller la chercher dans le menu du compilateur   "<strong>croquis</strong>" =&gt;&gt;"<strong>inclure</strong> <strong>une</strong> <strong>bibliothèque</strong>" comme illustré ci-dessous.</p>
<p><a href="https://plaisirarduino.fr/?attachment_id=1669"><img loading="lazy" decoding="async" class="aligncenter wp-image-1669 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/02-Bibliotheque..png" alt="02-bibliotheque" width="598" height="645" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/02-Bibliotheque..png 598w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/02-Bibliotheque.-278x300.png 278w" sizes="auto, (max-width: 598px) 100vw, 598px" /></a>Vous y retrouverez toutes <strong>les bibliothèques incluses dans le compilateur Arduino</strong>. Il suffit de cliquer sur l'une d'elle pour installer la <span style="text-decoration: underline;"><strong>directive d'inclusion</strong></span> dans notre programme.</p>
<p><span style="text-decoration: underline;"><strong>Exemple:</strong> </span></p>
<p><img loading="lazy" decoding="async" class=" wp-image-1652 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/09/01-Bibliotheque..png" alt="01-bibliotheque" width="384" height="88" /></p>
<p><strong><span style="color: #808000;">#include </span></strong>de l'anglais veut dire <strong><span style="text-decoration: underline;">inclure </span></strong><span style="text-decoration: underline;">en français c'est</span><strong><span style="text-decoration: underline;"> la directive d'inclusion </span>. </strong>Ce terme <strong>ordonne</strong><span id="mt1" class="sentence SentenceHover" data-guid="ad1276e51a38dca5db95deefc4101ddb" data-source="Tells the preprocessor to treat the contents of a specified file as if they appear in the source program at the point where the directive appears. "><strong> au compilateur de traiter le contenu d'un fichier</strong> de la bibliothèque spécifié à son nom, <strong>comme s'il faisait partie du programme principal.</strong></span></p>
<p>La <span style="text-decoration: underline;"><strong>directive d'inclusion</strong></span> se présente sous cette forme  <strong><span style="color: #808000;">#include</span></strong> <strong>&lt;<span style="color: #ff6600;">nomDeLaBibliothèque</span>.h&gt;.</strong></p>
<p>Il ne faut pas oublier que pour que le compilateur trouve<span style="text-decoration: underline;"><strong> la bibliothèque à </strong><strong>inclure,</strong></span> il faut lui spécifier un <span id="mt26" class="sentence" data-guid="c43308baab363dd61cc56e25edd7e3a7" data-source="If you enclose a complete, unambiguous path specification for the include file between double quotation marks (&quot; &quot;), the preprocessor searches only that path specification and ignores the standard directories.">chemin d'accès nommé entre  <strong><span style="text-decoration: underline;">&lt; &gt; </span></strong></span><span id="mt26" class="sentence" data-guid="c43308baab363dd61cc56e25edd7e3a7" data-source="If you enclose a complete, unambiguous path specification for the include file between double quotation marks (&quot; &quot;), the preprocessor searches only that path specification and ignores the standard directories."><span style="text-decoration: underline;"><strong>guillemets.</strong></span> </span><span id="mt26" class="sentence" data-guid="c43308baab363dd61cc56e25edd7e3a7" data-source="If you enclose a complete, unambiguous path specification for the include file between double quotation marks (&quot; &quot;), the preprocessor searches only that path specification and ignores the standard directories.">Le compilateur recherchera les termes du fichier entre guillemets.<br />
</span></p>
<p>Le <strong>.h</strong> spécifie le type de fichier. <strong>H</strong> vient du terme anglais <strong>Header</strong> qui veut dire<strong> entête. </strong>C'est donc pour spécifier un fichier dit d'entête.</p>
<p><strong>Le but étant ici de savoir comment les mettre en place, </strong>nous ne rentrerons pas dans les détails sur leurs constructions car cela sera abordé dans un autre tutoriel<strong><em><span style="color: #0000ff;">.</span></em></strong></p>
<p><em>Vous connaissez à présent la marche à suivre pour installer les bibliothèques de votre choix dans vos projets.</em></p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">Merci.</span></strong></h3>
<h4 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/">Plaisir.Arduino.fr </a></span></span></strong></h4>
<h3 style="text-align: center;"><strong><span style="text-decoration: underline; color: #0000ff;">FIN.</span></strong></h3>
<p>Cet article <a href="https://plaisirarduino.fr/bibliotheque/">Bibliothèque, comment l&rsquo;installer ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Fonctions, comment créer et utiliser les fonctions ?</title>
		<link>https://plaisirarduino.fr/les-fonctions/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Mon, 14 Nov 2016 20:29:27 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=1815</guid>

					<description><![CDATA[<p>Les fonctions Qu'est-ce qu'une fonction? Pour commencer, vous avez déjà, peut-être sans le savoir, exploiter une fonction. Les fonctions exécutent des tâches de travail pour lesquelles elles sont dédiées. Prenons le cas de setup() et loop() qui ont pour tâche d'exécuter les instructions contenues dans leurs blocs {}. Plus précisément, &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/les-fonctions/">Fonctions, comment créer et utiliser les fonctions ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Les fonctions</span></span></strong></h1>
<h2 style="text-align: left;"><span style="text-decoration: underline;"><strong>Qu'est-ce qu'une fonction?</strong></span></h2>
<p style="text-align: left;">Pour commencer, vous avez déjà, peut-être sans le savoir, exploiter une fonction. Les fonctions exécutent des tâches de travail pour lesquelles elles sont dédiées. Prenons le cas de <strong><span style="color: #808000;">setup</span>()</strong> et <strong><span style="color: #808000;">loop</span>()</strong> qui ont pour tâche d'exécuter les instructions contenues dans leurs blocs<strong> {}</strong>. Plus précisément, &nbsp;<strong><span style="color: #808000;">loop</span></strong>() a pour tâche de réitérer en boucle l'exécution des instructions et<span style="color: #808000;"> setup</span>() de les exécuter une seule fois.</p>
<p style="text-align: left;">Bien évidemment, vous savez que <span style="text-decoration: underline;"><strong><span style="color: #808000; text-decoration: underline;">loop</span>(){}</strong> est<strong> la fonction principale du programme</strong></span> à l’intérieur de laquelle, nous utilisons d'autres fonctions.</p>
<p style="text-align: left;">Il y a bien sûr <strong>les fonctions pré-définies dans L'IDE</strong> telles que<strong><span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/boucle-for/"> for()</a></span></span>,<span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/switch-case/"> switch()</a></span>, </span></strong>ou<span style="text-decoration: underline;"><strong><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/les-entrees-sortie-de-la-platine-arduino/"> digitalWrite();</a> </span></strong></span>que nous utilisons souvent.</p>
<p style="text-align: left;">N'oublions pas non plus,<strong> les classes qui ont aussi des "fonctions" accessibles depuis<span style="text-decoration: underline;"> l'IDE</span></strong> comme par exemple la classe<span style="text-decoration: underline;"><a href="https://plaisirarduino.fr/le-moniteur-serie/"><strong><span style="color: #3366ff; text-decoration: underline;"> Serial</span></strong></a></span> et sa fonction<span style="text-decoration: underline;"><a href="https://plaisirarduino.fr/le-moniteur-serie/"><strong> <span style="color: #3366ff; text-decoration: underline;">begin()</span></strong></a></span> qui permet de configurer le port série<strong><span style="color: #3366ff;">&nbsp;</span><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/le-moniteur-serie/">Serial.begin();</a></span></span></strong></p>
<p style="text-align: left;">Et pour finir,&nbsp;<strong>les fonctions pré-définies par les <span style="text-decoration: underline;">bibliothèques</span></strong> comme par exemple <strong>&lt;</strong><span style="color: #ff9900;">Servo</span>.h&gt; qui nous apporte au travers des <strong>objets</strong> qui leurs sont rattachés des fonctions comme par exemple <strong>servo.</strong><span style="color: #ff9900;">write</span>(paramètres);&nbsp; ici "<strong>servo</strong>" est notre objet et il utilise la fonction <strong><span style="color: #ff9900;"> write</span>()</strong>;</p>
<p style="text-align: left;">Nous comprenons ainsi qu'elles sont <strong><span style="text-decoration: underline;">utiles pour l'exécution de tâches répétitives et évitent alors la réécriture des lignes de codes à chaque fois que se présente une tâche</span>.</strong></p>
<p style="text-align: left;">Mais l'aspect le plus important d'une fonction<strong> lorsque l'on fait appelle à elle, c'</strong>est que <strong>nous attendons un retour de résultat</strong> à la fin de son accomplissement.</p>
<p style="text-align: left;"><strong>De plus, il vous est possible de réaliser des fonctions qui vous sont propres. </strong><strong> Il existe différentes façons de les construire!</strong><span style="color: #0000ff;">&nbsp;C'est cela que nous allons voir! Comment les construire et quelles sont &nbsp;leurs particularités !</span></p>
<p style="text-align: left;">Un peu de patience !</p>
<h2><span style="text-decoration: underline;"><strong>Comment se construit une fonction?</strong></span></h2>
<p>Elle se présente sous cette forme.</p>
<p style="text-align: left;"><strong><span style="color: #0000ff;">Type de fonction</span> Nom de la fonction (<span style="color: #ff0000;">paramètre1,paramètre2, ..., </span>) {<span style="color: #008000;"> Bloc d'instruction de la fonction</span>} </strong>//Format d'une fonction.<strong><br />
</strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-2221 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/01-fonctions.png" alt="Format de fonction" width="557" height="22" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/01-fonctions.png 405w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/01-fonctions-300x12.png 300w" sizes="auto, (max-width: 557px) 100vw, 557px" /></p>
<p style="text-align: left;">Nous voyons ci-dessus qu'il faut<strong> définir un<span style="text-decoration: underline;"> <span style="text-decoration: underline; color: #3366ff;"> <a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">type </a></span></span>à nos fonctions</strong>.</p>
<p style="text-align: left;">Que veut dire <strong><span style="color: #33cccc;">void</span></strong> ? &nbsp;Cela veut dire "<strong>vide"</strong> et signifie qu'une fonction de ce&nbsp;<strong><span style="text-decoration: underline;"><span style="text-decoration: underline; color: #3366ff;"> <a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">type </a></span></span>ne renvoie aucune valeur.</strong> Elle sont dites muettes. Patientez un peu, pour en savoir plus sur le renvoi des valeurs nous l'aborderons plus tard.</p>
<p style="text-align: left;">Il est courant de trouver<strong><span style="color: #33cccc;"> void</span> entre les parenthèses d'une fonction</strong> pour simplement dans ce cas indiquer qu'elle n'a aucun paramètre.<strong><span style="text-decoration: underline;">&nbsp;<span style="text-decoration: underline; color: #3366ff;"> <a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">type </a></span></span></strong> <strong>fonction (<span style="color: #33cccc;">voi</span><span style="color: #33cccc;">d</span>); .</strong></p>
<p style="text-align: left;"><strong>Pour en revenir au&nbsp;<span style="text-decoration: underline;"><span style="text-decoration: underline; color: #3366ff;"> <a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">type </a></span></span>d'une fonction, il dépendra de la valeur attendue par vous,&nbsp;</strong>c'est à vous de le définir. Une fonction typée&nbsp;<strong><span style="color: #33cccc;"> int</span></strong> renverra systématiquement une valeur de ce type. Par défaut, le programme renverra en type <strong><span style="color: #33cccc;">int</span></strong>.</p>
<p style="text-align: left;">Exemples de type de fonction . <img loading="lazy" decoding="async" class=" wp-image-1840 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/02-fonctions.png" alt="Exemple de fonction typés" width="446" height="145" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/02-fonctions.png 369w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/02-fonctions-300x98.png 300w" sizes="auto, (max-width: 446px) 100vw, 446px" /></p>
<p style="text-align: left;">Notre exemple ci-dessus, illustre également qu<strong>'il faut donner <span style="text-decoration: underline;">un nom symbolique</span> à une fonction</strong>. Dans notre exemple c'est "<strong>fonction</strong>" mais pour une fonction que vous créerez vous-même, c'est à vous de choisir le nom le plus judicieux rattaché à son utilité.</p>
<p style="text-align: left;">Parlons à présent des<strong> paramètres contenus entre parenthèses</strong> ! Ils définissent par leurs valeurs le résultat attendu par le traitement de la fonction. Voici un exemple. <strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;"><img loading="lazy" decoding="async" class=" wp-image-1842 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/03-fonctions.png" alt="03-fonctions" width="472" height="27" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/03-fonctions.png 367w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/03-fonctions-300x17.png 300w" sizes="auto, (max-width: 472px) 100vw, 472px" /></span></span></strong></p>
<p style="text-align: left;">Vous constatez qu'<strong>il faut également indiquer un <span style="text-decoration: underline; color: #3366ff;"> <span style="text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">type </a></span></span>à nos paramètres</strong>. Ils seront utiles et exploités dans le<strong> bloc {}</strong> de la fonction pour exécuter sa tâche. Le bloc est la zone de traitement des instructions qui y seront inscrites. Dans ce bloc, vous pouvez déclarer des<span style="text-decoration: underline; color: #3366ff;"> <strong><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></strong></span> qui seront locales à notre fonction.</p>
<p style="text-align: left;">Maintenant que l'on connaît la construction d'une fonction, on peut passer à son exploitation et à son utilisation.</p>
<h2 style="text-align: left;"><span style="text-decoration: underline;"><strong>Comment déclarer et appeler une fonction ?</strong></span></h2>
<p>Tout d'abord, <strong> pour la créer,</strong> comme une<span style="color: #3366ff;"> <span style="text-decoration: underline;"><strong><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variable</a></strong></span>,</span> <strong>une fonction doit être "déclarée"</strong>. Son appel doit être possible à tout moment de notre programme et vous comprendrez qu'elle soit déclarée<strong> de façon globale</strong>.</p>
<p>C'est-à- dire que cela se fera <strong>en dehors de la fonction<span style="color: #808000;"> loop</span>() et de toutes autres fonctions</strong>. L'emplacement <strong>avant ou après est possible,</strong> c'est à vous d'adopter celle qui vous convient. De préférence et par clarté de lecture programme nous préférons les placer après la fonction <strong><span style="color: #808000;">loop</span>()</strong>.</p>
<p>Nous y voici ! Créons notre première fonction! Nous l’appellerons<strong> "fonction".</strong></p>
<h4><strong><span style="text-decoration: underline;">Déclarer sa fonction.</span></strong></h4>
<p>D'abord <strong>"Déclarons" , après la boucle<span style="color: #808000;"> loop</span>() notre fonction en type<span style="color: #33cccc;"> void</span></strong><strong> et sans paramètres</strong><strong>. Enfin,</strong>&nbsp;nous lui&nbsp; donnons comme<strong> instruction d'envoyer un message</strong> au <strong><span style="color: #3366ff;"><span style="text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/le-moniteur-serie/">moniteur série</a></span>.</span></strong></p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1855 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/04-fonctions-e1476997384198.png" alt="04-fonctions" width="525" height="137" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/04-fonctions-e1476997384198.png 525w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/04-fonctions-e1476997384198-300x78.png 300w" sizes="auto, (max-width: 525px) 100vw, 525px" /></p>
<p>Comme on pouvait s'y attendre...! &nbsp;Si vous tentez de téléverser le programme; à ce stade il ne se passera rien! Effectivement,&nbsp;<strong>&nbsp;une fonction doit être appelée</strong> pour qu'elle s’exécute. On dit <strong>faire appel de la fonction et cela se passe dans le programme principal<span style="color: #808000;">&nbsp;loop</span>().<br />
</strong></p>
<h4><span style="text-decoration: underline;"><strong>Appeler sa fonction.</strong></span></h4>
<p>Il faut tout d'abord connaître<strong> de quelle manière on l'appelle</strong>. Il suffit d'<strong>inscrire le nom de la fonction suivi de ses parenthèses "()" et ponctuer d'un point virgule ";" dans le bloc {} de la fonction <span style="color: #808000;">loop</span>()</strong><strong>. </strong>Pour être plus précis, ci-dessous un schéma d'appel de la fonction.</p>
<p><img loading="lazy" decoding="async" class="wp-image-1894 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/14-fonctions-e1477040192551.png" alt="14-fonctions" width="373" height="241" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/14-fonctions-e1477040192551.png 511w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/14-fonctions-e1477040192551-300x194.png 300w" sizes="auto, (max-width: 373px) 100vw, 373px" /></p>
<p>Voir l' exemple ci-dessous.</p>
<p><img loading="lazy" decoding="async" class="wp-image-1878 size-full aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/05-fonctions-e1477033923230.png" width="297" height="122"></p>
<p>Notez que nous utiliserons<strong><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/la-boucle-while/"> while(1);</a></span></span></strong> pour une lecture plus confortable au <strong><span style="color: #3366ff;"><span style="text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/le-moniteur-serie/">moniteur série</a></span></span></strong>. Vous pouvez maintenant téléverser le programme et voir le résultat.</p>
<p><img loading="lazy" decoding="async" class="wp-image-1887 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/06-fonctions-e1477037257420.png" alt="06-fonctions" width="291" height="32"></p>
<p><strong>La fonction s’exécute,</strong> c'est déjà un bon début ! Voyons maintenant comment l'exploiter!</p>
<h2><strong><span style="text-decoration: underline;">Comment exploiter une fonction?</span></strong></h2>
<h4><span style="text-decoration: underline;"><strong>Retour de fonction.</strong></span></h4>
<p>Bien évidemment, vous attendrez de ces dernières qu'elles vous renvoient le résultat de leur travail pour ensuite l'exploiter.<strong> Pour récupérer et manipuler la donnée</strong> <strong>d'une fonction après l'avoir appelé, il va nous falloir une <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variable </a></span></span>pour la stocker</strong>.</p>
<p>L'aspect le plus spécifique du<strong> retour de fonction</strong> est qu'il<strong> doit être ordonné par une instruction qui s’appelle <span style="color: #808000;">return<span style="color: #000000;">()</span></span>; .<br />
</strong></p>
<p><strong> <span style="color: #808000;">return<span style="color: #000000;">(<span style="color: #ff0000;">Paramètre de retour</span>); //Instruction de renvoi de données.</span></span></strong><img loading="lazy" decoding="async" class="wp-image-1866 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/07-fonctions.png" alt="07-fonctions" width="139" height="29"></p>
<p>Dans un premier temps, commençons par examiner notre fonction. <span style="color: #808000;"><span style="color: #000000;">Il va nous falloir <strong>une valeur à retourner, ce qui implique une <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variable</a></span></span> qui la contienne.</strong></span></span> Puis, nous l'<strong>intégrerons comme paramètre à<span style="color: #808000;"> return</span>().</strong></p>
<p>En second temps, &nbsp;<strong>déclarons une <span style="color: #808000;"><span style="color: #000000;"><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variable </a></span></span></span></span>pour stocker le retour de la fonction</strong> puis <strong>affichons le résultat</strong> de cette valeur au <strong><span style="color: #3366ff;"><span style="text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/le-moniteur-serie/">moniteur série</a></span></span></strong>.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1877 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/08-fonctions-e1477033544468.png" alt="08-fonctions" width="531" height="389" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/08-fonctions-e1477033544468.png 531w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/08-fonctions-e1477033544468-300x220.png 300w" sizes="auto, (max-width: 531px) 100vw, 531px" /></p>
<p>Malgré cela vous allez constater, lors du téléversement, que le résultat est une erreur signalée par le compilateur.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1869 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/09-fonctions.png" alt="09-fonctions" width="471" height="112" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/09-fonctions.png 471w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/09-fonctions-300x71.png 300w" sizes="auto, (max-width: 471px) 100vw, 471px" /></p>
<p><span id="result_box" class="short_text" lang="fr"><span class="">Valeur</span> <span class="">nulle</span> <span class="">car elle</span> <span class="">devrait être <span class="alt-edited">ignorée.</span> Voilà ce que nous dit le compilateur.&nbsp;</span></span></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1871 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/10-fonctions-e1477002948622.png" alt="10-fonctions" width="432" height="18" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/10-fonctions-e1477002948622.png 432w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/10-fonctions-e1477002948622-300x13.png 300w" sizes="auto, (max-width: 432px) 100vw, 432px" /></p>
<p><span id="result_box" class="short_text" lang="fr"><span class=""> Comme nous l'avons dit en début de tutoriel, une fonction de type<strong> <span style="color: #33cccc;">void</span> ne peut pas retourner de valeur</strong> . D'autres messages apparaissent plus bas qui nous indiquent qu'une fonction<strong><span style="color: #33cccc;"> void</span> ne peut pas accepter le terme<span style="color: #808000;"> return</span>();</strong> car <strong>inadapté pour une fonction qui n'est pas faite (typée) pour renvoyer une valeur</strong>. </span></span></p>
<p><span id="result_box" class="short_text" lang="fr"><span class="">En conclusion, une fonction de type <strong><span style="color: #33cccc;">void</span></strong> ne fait qu’exécuter des instructions comme la fonction <strong><span style="color: #808000;"> <span style="color: #33cccc;">void</span> loop</span>().</strong></span></span></p>
<h4><strong><span style="text-decoration: underline;">Exploiter une fonction.</span></strong></h4>
<p>Enfin nous y voici !!! Pour qu'une fonction nous retourne une valeur, il va nous falloir <strong><span style="color: #000000;">lui attribuer un type autre que </span><span style="color: #33cccc;">void</span><span style="color: #000000;">.</span></strong> Le type <strong><span style="color: #33cccc;">int</span></strong> par exemple est le plus simple pour commencer et comprendre le principe. En conséquence, nous <span style="color: #000000;">modifions le type de <strong>notre fonction</strong></span> par <strong><span style="color: #33cccc;">int<span style="color: #000000;">.</span></span></strong> Puis, on regarde le résultat au moniteur !!</p>
<p><img loading="lazy" decoding="async" class="wp-image-1885 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/12-fonctions.png" alt="12-fonctions" width="366" height="62"></p>
<p>Tout se déroule comme prévu. La fonction s’exécute et nous retourne sa valeur de retour.</p>
<p>Mais, en réalité,<strong> il existe un moyen plus simple d'exploiter le retour des fonctions</strong>. Plus précisément, &nbsp;il n'est<strong> pas utile dans tous les cas d'utiliser une <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variable </a></span></span>de stockage</strong>. Par exemple, pour afficher la valeur de retour au moniteur, il suffit de<span style="text-decoration: underline;"><strong> l'inscrire comme paramètre à la fonction <span style="color: #ff9900; text-decoration: underline;">print</span>();</strong></span>. Inspectez ci-dessous la variante de notre programme d'origine.</p>
<p><img loading="lazy" decoding="async" class=" wp-image-1889 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/13-fonctions.png" alt="13-fonctions" width="656" height="420" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/13-fonctions.png 533w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/13-fonctions-300x192.png 300w" sizes="auto, (max-width: 656px) 100vw, 656px" /></p>
<p>Après cela vous constaterez qu'avec moins de ligne; le programme devient&nbsp;<strong>plus simplifié </strong>et surtout, nous sommes à présent<strong> capable d'obtenir le retour d'une fonction</strong>.</p>
<h3><strong><span style="text-decoration: underline;">Comment créer une fonction paramétrée?</span> </strong></h3>
<p><strong>Un aspect plus spécifique des fonctions</strong> est de<strong> pouvoir admettre des valeurs extérieures à elles-mêmes par le biais de leurs paramètres dit formels. </strong> Elle vont ensuite nous retourner une donnée finale en fonction des valeurs données en paramètres exploités dans leurs blocs.</p>
<p>Ça y est nous y sommes !!</p>
<p>Premièrement,&nbsp;<strong>déclarons les paramètres entre les parenthèses</strong> <strong>"()</strong>" de la fonction <strong>en leur spécifiant un type de données</strong>. De toute évidence, cela se fera <strong>dans la partie "déclarative" de la fonction</strong>.</p>
<p>Exemple:</p>
<p><img loading="lazy" decoding="async" class="wp-image-1897 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/15-fonctions.png" alt="15-fonctions" width="440" height="60" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/15-fonctions.png 337w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/15-fonctions-300x41.png 300w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/15-fonctions-332x46.png 332w" sizes="auto, (max-width: 440px) 100vw, 440px" /></p>
<p>Ci-dessus, nous avons <strong>déclaré trois <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span> de type</strong> <strong><span style="color: #33cccc;">int</span></strong> .</p>
<p><strong>Mais que faire de nos paramètres au sein de la fonction ? Et bien? ce que l'on en veut !</strong>&nbsp;On peut&nbsp; les additionner, les soustraire ou autres. On peut aussi les utiliser dans un conditionnement<span style="text-decoration: underline;"><strong><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/if-if-else/"> if()</a></span></strong></span>. N<span style="text-decoration: underline;"><strong>ous constatons ici que la fonction est un sous programme</strong>.</span></p>
<p>Tout d'abord, il faut comprendre que <strong>les paramètres sont utiles pour intégrer à volonté des valeurs</strong> <strong>extérieures à la fonction</strong>. Ces derniers sont<strong>&nbsp;renseignés depuis le programme principal de façon "Manuelle ou Systématique", via des <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a>.</span></span></strong></p>
<p><img loading="lazy" decoding="async" class="wp-image-1901 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/16-fonctions.png" alt="16-fonctions" width="467" height="40" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/16-fonctions.png 385w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/16-fonctions-300x26.png 300w" sizes="auto, (max-width: 467px) 100vw, 467px" /></p>
<p>Au travers des fonctions standards de l'IDE, vous savez déjà renseigner des fonctions de façon manuelle donc nous passerons de suite à la <strong>manière Systématique. </strong>Pour notre exemple,&nbsp;<strong>nous ferons un calcul simple</strong>.</p>
<h3><strong><span style="text-decoration: underline;">Comment utiliser les paramètres ?</span></strong></h3>
<p><strong>L'exploitation des paramètres se fera depuis le programme principal et</strong> avant toutes choses <strong>nous créons trois <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span> qui contiendront les valeurs</strong> (données) à manipuler. Puis nous <strong>intégrons ces <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span>&nbsp;en &nbsp;paramètres à notre fonction. </strong>Comme ci-dessous.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1906 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/17-fonctions.png" alt="17-fonctions" width="603" height="442" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/17-fonctions.png 603w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/17-fonctions-300x220.png 300w" sizes="auto, (max-width: 603px) 100vw, 603px" /></p>
<p>Voici le résultat ! Amusez-vous à changer les valeurs dans les variables !</p>
<p><img loading="lazy" decoding="async" class="wp-image-1907 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/18-fonctions.png" alt="18-fonctions" width="385" height="43"></p>
<p>Bravo !</p>
<p><em>A partir de là, vous commencerez à penser à vos programmes d'une façon différente. Il faut s'imaginer que votre programme et comme une poupée russe.</em></p>
<p><span style="text-decoration: underline;"><strong>NOTE D'EXPLOITATION: </strong></span></p>
<ul>
<li>Il faut savoir&nbsp;que lorsque l'on crée une fonction paramétrée,<strong> les <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span> affectées au paramètres doivent avoir des noms symboliques à leurs exploitations.</strong> Prenons le cas de notre exemple, si le premier paramètre est un coefficient, il est judicieux de lui donner un nom du genre "coef". Notre exemple illustre bien que<strong> si l'on inverse les <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a>,</span></span> le résultat ne sera pas le même.</strong> L'utilisation de plusieurs paramètres demande donc une certaine organisation.</li>
<li>Bien sûr,<strong> il est tout à fait possible</strong> -et vous serez tenté- <strong>de créer des retours de fonctions en utilisant des&nbsp;<span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span></strong> globales mais cette méthode vous demandera un appel systématique de ces dernières, à chaque besoin et de prendre garde de ne pas vous emmêler les pinceaux avec la multitudes de <strong><span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span></strong> que vous pourrez en "sortir". Par principe de clarté logique et à juste titre par <strong><span style="color: #808000;">return</span>(),</strong> nous partons du principe qu'une fonction n'a de retour qu'une seule donnée utile.</li>
</ul>
<h3><span style="text-decoration: underline;"><strong>Une fonction pour une fonction !</strong></span></h3>
<p>L'utilisation d'<strong>une fonction comme paramètre</strong> est également possible. Là, on entre dans une dimension autre ! Etant donné qu'<strong>une fonction retourne une donnée,</strong>&nbsp;cette dernière <strong>peut être exploitée par un paramètre.</strong> Je vous invite à faire l'essai avec l'exemple ci-dessous. Remarquez que nous l'avons déjà fait avec la fonction de <a href="https://plaisirarduino.fr/le-moniteur-serie/"><strong><span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;">Serial.println();</span></span></strong></a></p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1923 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/19-fonctions.png" alt="19-fonctions" width="646" height="527" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/19-fonctions.png 646w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/19-fonctions-300x245.png 300w" sizes="auto, (max-width: 646px) 100vw, 646px" /></p>
<p>Le résultat est le suivant. Nous retrouvons alors trois fonctions imbriquées les unes dans les autres par leurs appels. <em>Le principe de poupée russe devient parlant maintenant.</em></p>
<p><img loading="lazy" decoding="async" class="wp-image-1925 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/20-fonctions.png" alt="20-fonctions" width="422" height="36"></p>
<h3><span style="text-decoration: underline;"><strong>Une fonction tentaculaire !</strong></span></h3>
<p>Imaginez ce que vous pourrez faire à<strong> l'aide d'un <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/tableau-de-donnees/">tableau</a></span></span> et de vos paramètres</strong> !! Considérons, par exemple, que notre fonction gère trois éléments différents. En supposant que chaque élément possède un <strong><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/tableau-de-donnees/">tableau</a></span></span></strong> de données qui lui est propre.</p>
<p>Notre fonction va&nbsp;<strong>traiter et attribuer une valeur à chaque élément en fonction de ces données propres</strong>. Prenons notre fonction de base et essayons!</p>
<p><img loading="lazy" decoding="async" class="wp-image-1927 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/21-fonctions.png" alt="21-fonctions" width="575" height="498" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/21-fonctions.png 514w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/21-fonctions-300x260.png 300w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p>Nous avons de ce fait, répété trois fois la même action pour trois éléments différents de données différentes. Et le résultat est évidemment différent.</p>
<p><img loading="lazy" decoding="async" class="wp-image-1929 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/22-fonctions.png" alt="22-fonctions" width="336" height="76"></p>
<p>A condition de bien s'organiser, cela ouvre des possibilités sans limites. <strong>Nous pourrions aller plus loin</strong> en créant un programme qui <strong>générerait automatiquement les données du&nbsp;<span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/tableau-de-donnees/">tableau</a></span></span></strong> de chaque éléments <strong>par l'acquisition de signaux d'entrées analogiques ou autres,</strong> <strong>transmise à des <span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/variables/">variables</a></span></span></strong> propres<strong> à chaque tableau</strong>. Voyez ci-dessous une ébauche de ce que cela pourrait donner. Nous vous laissons l'exercice de créer des variables de votre cru pour exploiter cette solution. <strong>A vous de jouer !!</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1931" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/23-fonctions.png" alt="23-fonctions" width="527" height="492" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/23-fonctions.png 527w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/10/23-fonctions-300x280.png 300w" sizes="auto, (max-width: 527px) 100vw, 527px" /></p>
<p>Vous connaissez à présent&nbsp; les bases et les outils utiles pour comprendre, créer et exploiter vos propres fonctions. Nous vous invitons à <strong><span style="text-decoration: underline;"><span style="color: #3366ff;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/telechargement/">télécharger</a></span></span></strong> les sketchs référents à ce tutoriel pour une mise en pratique.</p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">Merci.</span></strong></h3>
<h4 style="text-align: center;"><strong><span style="color: #3366ff;"><a style="color: #3366ff;" href="https://plaisirarduino.fr/">PlaisirArduino.fr</a></span></strong></h4>
<h3 style="text-align: center;"><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">FIN.</span></strong></span></h3>
<p>Cet article <a href="https://plaisirarduino.fr/les-fonctions/">Fonctions, comment créer et utiliser les fonctions ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>switch() { case: }</title>
		<link>https://plaisirarduino.fr/switch-case/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Tue, 04 Oct 2016 04:02:10 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=1218</guid>

					<description><![CDATA[<p>switch() { case: break; default:} Ma définition: switch de l'anglais veux dire en français commutateur, changer ou aiguiller. Et case de l'anglais veux dire cas qui exprime ce qui doit arriver si des condition sont réunis pour sa réalisation. Comme cela nous le dit switch va nous permettre de commuter &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/switch-case/">switch() { case: }</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1><strong><span style="color: #808000;">switch</span><span style="color: #000000;">() {</span><span style="color: #808000;"> case</span><span style="color: #000000;">: <span style="color: #808000;">break</span>; <span style="color: #808000;">default<span style="color: #000000;">:</span></span>}</span></strong></h1>
<p><span style="text-decoration: underline;"><strong>Ma</strong></span><strong><span style="text-decoration: underline;"> définition:</span><span style="color: #808000;"> switch</span> </strong>de l'anglais veux dire en français <strong>commutateur</strong>,<strong> changer</strong> ou <strong>aiguiller</strong>. Et <strong><span style="color: #808000;">case</span></strong> de l'anglais veux dire<strong><span style="color: #000000;"> cas</span></strong> qui exprime ce qui doit arriver si des condition sont réunis pour sa réalisation.</p>
<p>Comme cela nous le dit <strong><span style="color: #808000;">switch</span></strong> va nous permettre de <span style="text-decoration: underline;">commuter ou changer de choix en l'aiguillant en fonction des cas proposés</span>. Cette instruction nous autorise donc à des <strong>choix multiples structurellement simple</strong> contrairement à <strong><span style="color: #808000;">if</span></strong> qui ne nous offre que deux choix possibles et demande des imbrications multiples plus trop illisibles pour arriver au même résultat.</p>
<p>En premier lieu <strong><span style="color: #808000;">switch case</span> a besoins que l'on utilise l'instruction<em> <span style="text-decoration: underline; color: #808000;">break;</span></em></strong> (vue dans <strong><span style="text-decoration: underline;"><em><span style="color: #808000; text-decoration: underline;">while</span></em></span></strong>) à chaque fin de cas pour sortir de sont bloc d'instructions. Sans cela <strong><span style="color: #808000;">switch</span></strong> exécutera toute les instructions de cas contenu dans son bloc en partant de la sélection active.</p>
<p><strong><span style="color: #808000;">switch</span> <span style="color: #808000;">case</span></strong> possède une particularité. Grâce l'instruction <strong><span style="color: #808000;">default</span>:</strong> qui veut dire <strong><span style="color: #000000;">défaut</span></strong> en français <strong><span style="color: #808000;">switch case</span></strong> peut agir par défaut et exécuter des actions spécifiques et définis si aucuns de ses cas n'est réalisés. Si vous n'en avez pas l'utilité Il n'est pas nécessaire de l'utiliser dans le bloc. <strong><span style="color: #808000;">default</span>:</strong> est une option.</p>
<h2><span style="text-decoration: underline;">Sa construction</span></h2>
<p><strong><span style="text-decoration: underline;">Elle est construite en trois parties:</span><br />
</strong></p>
<ul>
<li><strong>l'instruction</strong> qui contient entre parentes <strong><span style="color: #ff0000;">une variable de contrôle</span></strong> utile à l'exploitation de<strong><span style="color: #808000;"> switch</span></strong>.</li>
<li><strong>Un bloc</strong> dans le quel sont réunis les<strong><span style="color: #ff9900;"> cas d’exécutions</span></strong> définis par la valeur de la une donnée qui lui est attribuée. On la nommera ici <strong><span style="color: #0000ff;">donnée sélective</span></strong>. On  y trouvera aussi <strong><span style="color: #808000;">default</span></strong>: qui n'a pas de donnée sélective.</li>
<li><strong><span style="color: #008000;">Les instructions programmée</span></strong> pour chaque cas de <strong><span style="color: #808000;">case</span></strong> suivis de l'instruction <span style="color: #808000;">break;</span>.</li>
</ul>
<p><span style="text-decoration: underline;"><strong>Elle se présente sous cette forme.</strong></span></p>
<p><strong><span style="color: #808000;">switch</span></strong> (<strong><span style="color: #ff0000;">Variable de contrôle</span></strong>) { <strong><span style="color: #808000;">case</span></strong> <strong><span style="color: #0000ff;">donnée sélective</span></strong> : <strong><span style="color: #008000;">instructions programmées; <span style="color: #808000;">break</span></span></strong><span style="color: #008000;"><span style="color: #000000;">};</span></span></p>
<p><span style="text-decoration: underline;">Exemple:</span></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1407" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE.png" alt="SWITCH CASE" width="511" height="329" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE.png 511w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-300x193.png 300w" sizes="auto, (max-width: 511px) 100vw, 511px" /></a></p>
<h2><span style="text-decoration: underline;">Son fonctionnement</span></h2>
<p>Dans l'exemple ci dessus lorsque la <strong><span style="color: #ff0000;">variable de contrôle "var"</span> </strong>serra égale à la l'une des <strong><span style="color: #0000ff;">donnée sélective </span></strong><span style="color: #0000ff;"><span style="color: #000000;">de</span></span> <strong><span style="color: #808000;">case</span></strong> soit <span style="color: #0000ff;">0</span>, <span style="color: #0000ff;">1</span> ou <span style="color: #0000ff;">2</span> le programme affichera sa valeur et sortira du bloc <strong><span style="color: #808000;">switch</span></strong>. Si ce n'est pas le cas on exécute l'instruction <strong><span style="color: #808000;">default<span style="color: #000000;">:</span></span></strong><span style="color: #808000;"><span style="color: #000000;"> </span></span>pour afficher un message.</p>
<h3><strong><span style="text-decoration: underline;">Le regroupement de données sélectives.</span></strong></h3>
<p>Néanmoins il existe <strong>une autre manière d'utiliser les <span style="color: #0000ff;">données sélectives</span></strong> de<strong><span style="color: #808000;"> case</span></strong>. Il est possible de <strong>regrouper plusieurs <span style="color: #0000ff;">données sélectives</span></strong> pour exécuter qu'une seul instruction. Ainsi cela nous donne<strong> la possibilité de d’exécuter une instruction avec plusieurs cas</strong>.</p>
<p><span style="text-decoration: underline;">Exemple:</span></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-02.png"><img loading="lazy" decoding="async" class="size-full wp-image-1409 alignnone" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-02.png" alt="SWITCH CASE 02" width="471" height="359" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-02.png 471w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-02-300x229.png 300w" sizes="auto, (max-width: 471px) 100vw, 471px" /></a></p>
<p>Dans l'exemple ci dessus les cas de <strong><span style="color: #0000ff;">données sélectives</span></strong> impaire et paire sont regroupé pour exécuter l'instruction qui les suit. Il n'est donc <strong>pas utile de réitéré l'instruction pour chaque cas</strong> si ces dernier ont pour but de réaliser la même action.</p>
<h3><strong><span style="text-decoration: underline;">Utilisation d'un type char.</span></strong></h3>
<p>La variable de contrôle <strong><span style="text-decoration: underline;">doit être généralement de type<span style="color: #33cccc; text-decoration: underline;"> int</span></span> </strong>mais il est possible d'utiliser le type <strong><span style="color: #33cccc;">char </span></strong><span style="color: #000000;">avec</span> <strong><span style="color: #808000;">switch case</span></strong><span style="color: #000000;">. Donc il suffit de <span style="text-decoration: underline;">crée une variable ce type</span> et de <span style="text-decoration: underline;">renseigner les cas de la même manière.</span></span></p>
<p><span style="text-decoration: underline;">Exemple.</span></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-03.png"><img loading="lazy" decoding="async" class="size-full wp-image-1411 alignnone" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-03.png" alt="SWITCH CASE 03" width="427" height="175" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-03.png 427w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/05/SWITCH-CASE-03-300x123.png 300w" sizes="auto, (max-width: 427px) 100vw, 427px" /></a></p>
<p>Pour conclure avec l’exemple ci dessus. il  exécutera les instructions de cas en fonction de la variable "lettre".</p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">FIN.</span></strong></h3>
<p>Vous connaissez à présent les bases de <strong><span style="color: #808000;">switch case.</span> </strong></p>
<p>Il y de multiple façons d'exploiter<span style="color: #808000;"><span style="color: #000000;"> <strong> <span style="color: #808000;">switch</span> () { <span style="color: #808000;">case</span>:  }; </strong>. Vous</span></span> en découvrirez au fur et à mesure de votre progression et par la mise en pratique de vos projet.</p>
<p><em>Découvrez <strong><span style="color: #808000;">switch case</span></strong> <span style="color: #808000;"><span style="color: #000000;">en <a href="https://plaisirarduino.fr/telechargement/"><span style="color: #0000ff;">téléchargeant</span></a></span></span><span style="color: #000000;"> les sketchs référents de ce sujet. <strong>Merci</strong>.</span></em></p>
<p>Cet article <a href="https://plaisirarduino.fr/switch-case/">switch() { case: }</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>le moniteur série. Qu&#8217;est ce que c&#8217;est ?</title>
		<link>https://plaisirarduino.fr/le-moniteur-serie/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Sat, 10 Sep 2016 16:36:33 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=753</guid>

					<description><![CDATA[<p>Qu'est-ce que le moniteur série et à quoi ça sert ? Introduction. Pour commencer il se nomme "moniteur série" car il utilise la communication dit "série" entre votre "PC" et votre carte Arduino qui sont connectés via leurs ports "USB". Tout d’abord, il faut dire que le moniteur série est &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/le-moniteur-serie/">le moniteur série. Qu&rsquo;est ce que c&rsquo;est ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 style="text-align: center;"><span style="text-decoration: underline;"><strong><span style="color: #000000; text-decoration: underline;">Qu'est-ce que le moniteur série et à quoi ça sert ?</span></strong></span></h1>
<h3><span style="text-decoration: underline;"><strong>Introduction</strong>.</span></h3>
<p style="text-align: justify;">Pour commencer il se nomme <span style="color: #0000ff;"><strong>"moniteur série"</strong></span> car il utilise la communication dit "<strong>série</strong>" entre votre "PC" et votre carte Arduino qui sont connectés via leurs ports "USB".</p>
<p style="text-align: justify;">Tout d’abord, il faut dire que le moniteur série est <strong>un outil indispensable</strong> pour les tests de programmes. Il est utile pour <strong>avoir un retour de données</strong> et ainsi nous permet de <strong>déboguer</strong> les dysfonctionnements de nos programmes par des <strong>affichages séquencés des données utiles au traitement du bogue.</strong></p>
<h4 style="text-align: justify;"><strong><span style="text-decoration: underline;">La communication série.</span></strong></h4>
<p style="text-align: justify;">Pour ne pas entrer dans les détails de la communication série. C'est un mode de transmission (protocole)&nbsp; bit à bit des données sur deux conducteurs l'un <strong>RX</strong> (<strong>R</strong>éception) et l'autre <strong>TX </strong>(<strong>T</strong>ransmission). L' essentiel à savoir de la communication série est <span style="text-decoration: underline;">son débit</span> en <strong>bauds</strong> car il peut être différent d'un périphérique à un autre. Je dirai &nbsp;simplement que le <strong>bauds&nbsp;</strong>est une unité de mesure de débit qui correspond au nombre de bits transmis par seconde. Par exemple si nous avons 800 bauds, il y a 800 bits à la seconde. Il nous sera très <strong>utile de connaître son débit</strong> <strong>en bauds</strong> pour l'exploitation du moniteur avec la carte Arduino.</p>
<h3 style="text-align: justify;"><span style="text-decoration: underline;"><strong>Où l'activer ?</strong></span></h3>
<p>Il est représenté par une loupe et se trouve&nbsp; dans la barre d'outils en haut à droite du compilateur.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/lanceur-moniteur-série.png"><img loading="lazy" decoding="async" class=" wp-image-1069 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/lanceur-moniteur-série.png" alt="lanceur moniteur série" width="186" height="59"></a> Nous voyons apparaître une fenêtre.</p>
<h3><strong><span style="text-decoration: underline;">Comment se présente le moniteur ?</span></strong></h3>
<p>Commençons par examiner plus en détaille cette fenêtre dans laquelle apparaissent plusieurs commandes et deux zones blanches d'exploitation.</p>
<ul>
<li>Premièrement<span style="text-decoration: underline;"><strong> La grande zone au centre</strong></span> est la zone d'affichage des données reçues par le moniteur.</li>
<li>Deuxièmement<strong><span style="text-decoration: underline;"> La petite zone rectangulaire</span></strong>, en haut est une <strong>zone de saisie </strong>et bien-sûr<span style="text-decoration: underline;"><strong> le bouton</strong> <strong>Envoyer</strong></span> qui se trouve à sa droite permet la commande d'envoi des données saisies. On peut à l'aide du moniteur série envoyer des données vers l'Arduino qui s'occupera de les traiter grâce à la commande spécifique<em>.</em></li>
</ul>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Moniteur-serie-présentation..png"><img loading="lazy" decoding="async" class="alignnone wp-image-1070 size-full" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Moniteur-serie-présentation..png" alt="Moniteur serie présentation." width="541" height="303" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Moniteur-serie-présentation..png 541w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Moniteur-serie-présentation.-300x168.png 300w" sizes="auto, (max-width: 541px) 100vw, 541px" /></a></p>
<p>Troisièmement<strong><span style="text-decoration: underline;"> La case cochée "Défilement automatique"</span></strong> permet d’arrêter le défilement des données retournées par l'Arduino si on la décoche.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-coche-defilement-.png"><img loading="lazy" decoding="async" class="size-full wp-image-1082 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-coche-defilement-.png" alt="Mointeur série coche defilement" width="140" height="23"></a>Quatrièmement<span style="text-decoration: underline;"><strong> Le bouton de gauche en bas</strong></span> permet le réglage du mode de défilement des informations via une liste déroulante de choix.</p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-bouton-défilement.png"><img loading="lazy" decoding="async" class="size-full wp-image-1081 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-bouton-défilement.png" alt="Mointeur série bouton défilement" width="118" height="23"></a>Finalement <span style="text-decoration: underline;"><strong>Le bouton de droite en bas</strong></span>&nbsp; affiche une liste déroulante de choix qui va nous permettre de choisir la vitesse de transmission de notre moniteur série. Voyez comme les choix sont multiples et en unité bauds<em>.</em></p>
<p style="text-align: justify;"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-bouton-config.png"><img loading="lazy" decoding="async" class="size-full wp-image-1080 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-bouton-config.png" alt="Mointeur série bouton config" width="91" height="23"></a>Ensuite Une fois lancé,<strong> le moniteur doit être configuré</strong>. On doit lui attribuer un débit de traitement , en bauds, pour qu'il soit <strong>synchronisé</strong> <strong>à la même vitesse que l'Arduino</strong><em>.</em></p>
<h3 style="text-align: justify;"><strong><span style="text-decoration: underline;">Comment synchroniser tout ça ?</span></strong></h3>
<p style="text-align: justify;">Avant toute chose le moniteur série et la carte Arduino ont besoin d’être renseigné et de connaître la vitesse à laquelle ils vont travailler <strong><span style="text-decoration: underline;">si les deux périphériques n'ont pas le même débit (vitesse) ils ne se comprendront pas</span></strong>.</p>
<p style="text-align: justify;">En premier lieu cela dépend du <strong><span style="text-decoration: underline;">choix de l'utilisateur</span></strong>.</p>
<p style="text-align: justify;">Ce choix se fait <strong><span style="text-decoration: underline;">à deux endroits</span></strong>. Dans le "PC" <strong><span style="text-decoration: underline;">par le moniteur série</span></strong> lui-même et dans la carte Arduino<strong><span style="text-decoration: underline;"> via le compilateur</span></strong>. Tout ceci est dû à une horloge qui synchronise et fixe une cadence de traitement et d'envoi des données. C'est la raison pour laquelle Les valeurs <strong><span style="text-decoration: underline;">doivent être identiques.</span></strong></p>
<p>Imaginons par exemples une chaîne de production de <strong>deux machines "A et B"</strong> qui emballent dans des cartons un produit X. La machine "A" met le produit X dans les cartons et la machine B ferme le carton.<strong> La machine "A" met 1 produit par minute</strong> dans un carton et <strong>la machine "B" ferme 1 carton par minute</strong>. Jusque là, &nbsp;pas de problème, mais si j'augmente la cadence de la <strong>machine "A" à 2 produits par minute</strong>, Comme on pouvait s'y attendre il va se produire une <strong>saturation devant la machine "B" et par conséquent</strong> les cartons se retrouveront coincés, tomberont (être ignorés) et<strong> ne serons jamais fermés</strong> (lus). Pour notre synchronisation, c'est à peu près la même chose. <strong>Les deux périphériques doivent travailler à la même vitesse.</strong></p>
<h3 style="text-align: justify;"><span style="text-decoration: underline;"><strong>Configuration du moniteur série (IDE).</strong></span></h3>
<p>D'abord commençons par<strong> le moniteur série qui est plus directement accessible</strong>. C'est à nous de choisir et de définir le débit en bauds que l'on souhaite utiliser, donc il suffit donc de le <strong>sélectionner dans la liste déroulante qui se trouve en bas à droite du moniteur.</strong> A partir de là, nous avons configuré le débit de traitement du moniteur qui est en soit celle du "PC".</p>
<h3><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-liste-déroulante-.png"><img loading="lazy" decoding="async" class="size-thumbnail wp-image-1085 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-liste-déroulante--91x150.png" alt="Mointeur série liste déroulante" width="91" height="150"></a><span style="text-decoration: underline;"><strong>Comment configurer la vitesse de travail de l'Arduino?</strong></span></h3>
<p>Tout se passe dans le compilateur ou plus exactement lors de la configuration de notre programme dans la fonction <strong><span style="color: #808000;">setup</span>()</strong>.</p>
<h5><span style="text-decoration: underline;"><strong>Avant propos: Les classes.</strong> </span></h5>
<p>Il faut tout d’abord savoir qu'il existe ce que l'on appelle des<strong><span style="color: #0000ff;"> Classes</span> </strong>(que nous verrons mais bien plus tard). <strong>On distingue une Classe par la majuscule postée en début de mot</strong>. la caractéristique principale d'une <strong><span style="color: #0000ff;">Classe</span></strong> est de <strong>regrouper des fonctions spécifiques à un travail</strong> donné. Pour les plus avertis sur le sujet,<strong> celle-ci n'a pas besoin d’être appelée en déclaration pour que l'on puisse l'utiliser</strong>.</p>
<p style="text-align: justify;"><em><span style="color: #ff9900;"><span style="color: #000000;"><span style="color: #0000ff;">Une Classe</span> </span></span></em><em>est comme une caisse à outils dans laquelle je vais chercher l'outil dont j'ai besoins<span style="color: #ff6600;"><span style="color: #000000;">,</span></span><span style="color: #000000;"><strong> une fonction</strong> qui a une tâche définie et</span> qu'il me faut. Le tournevis ou la clé à molette ont des fonctions différentes. Vous découvrirez qu’il existe pas mal de grosses caisses et toutes avec des fonctions différentes à l’intérieur. </em></p>
<p style="text-align: justify;">Pour notre configuration nous aurons besoins en particulier de la classe nommé <strong><span style="color: #ff9900;">Serial</span></strong>. qui <strong>contient toutes les fonctions utiles à la gestion d'un port série. </strong>son travail est de <strong>gérer le traitement des données d'une communication série entre le moniteur série et le périphérique Arduino.</strong></p>
<h3 style="text-align: justify;"><span style="text-decoration: underline;">Les fonctions de la classe <strong><span style="color: #ff9900; text-decoration: underline;">Serial</span></strong>.</span></h3>
<p style="text-align: justify;">Ci-dessous vous avez les fonctions utiles à l'exploitation de la<strong> Classe <span style="color: #ff9900;">Serial</span>.</strong></p>
<p><em>Çà en fait des outils !! Il y a de quoi faire du bon boulot!</em></p>
<ul>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">begin</span></strong>(); Permet de configurer la vitesse de transmission du port série.</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">print</span>();</strong> Permet d'envoyer une donnée vers le moniteur série.</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">println</span>();</strong> Permet d'envoyer une donnée vers le moniteur série et fait un saut à la ligne "ln"</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">write</span>();</strong> Permet d'exploiter le format binaire, renvoie une chaîne de caractères en nombre de bits</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">read</span>();</strong> Permet de lire les données contenues dans le buffer</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">flush</span>();</strong> Permet de vider la mémoire tampon, la file d'attente, ou dit le "buffer" de la liaison série.</li>
<li style="text-align: justify;"><strong><span style="color: #ff9900;">available</span>();</strong> Permet de connaître si il y a des caractères disponibles pour lecture dans la mémoire tampon (buffer) du port série.</li>
</ul>
<p>Dan notre cas celle qui en particulier nous intéresse c'est <strong><span style="color: #ff9900;">begin</span>(),</strong></p>
<h3><span style="text-decoration: underline;"><strong>La configuration de la carte Arduino.</strong></span></h3>
<p>La fonction&nbsp; <strong><span style="color: #ff9900;">begin</span>();</strong> permet la configuration de la vitesse de transmission en bauds.</p>
<p>Elle se présente sous cette forme:</p>
<ul>
<li><strong><span style="color: #ff9900;">Serial</span>.<span style="color: #ff9900;">begin</span>(<span style="color: #0000ff;">Paramètre de configuration</span>); </strong>//Configuration de vitesse de transmission série.</li>
</ul>
<p>Le liens d'appel de <strong>"<span style="color: #ff9900;">begin</span>"</strong> avec <strong><span style="color: #ff9900;">Serial</span> </strong>est fait<strong> par le point</strong> entre les deux mots, il est appelé en langage C<strong> <em>membre de structure</em></strong>.</p>
<p>Parce que c'est une configuration, elle doit être <strong>appelée et paramétré à l'intérieur de la fonction "<span style="color: #33cccc;">void</span> <span style="color: #99cc00;">setup<span style="color: #000000;">()</span></span>".</strong></p>
<p>Ci dessous vous trouvez un exemple d'appel de cette fonction au travers de sa classe. le port série de la carte <strong>Arduino est configuré à 9600 bauds.</strong></p>
<p style="text-align: justify;"><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-setup-config.png"><img loading="lazy" decoding="async" class="wp-image-1086 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-setup-config.png" alt="Mointeur série setup config" width="374" height="134"></a>Ainsi nous avons configuré la vitesse de notre port série au même niveau de la carte Arduino.</p>
<p style="text-align: justify;">Finalement <span style="text-decoration: underline;"><strong>notre moniteur est prêt à être utilisé !</strong></span> Il ne reste donc plus qu'à créer le programme qui lui envoie des données à afficher.</p>
<h3 style="text-align: justify;"><span style="text-decoration: underline;"><strong>Recevoir des données au moniteur série.</strong></span></h3>
<p>Cette fois ci il nous faudra donc <strong>une fonction qui transmet nos données vers le moniteur série. </strong>De nouveau nous ferons appel à la classe <strong><span style="color: #ff9900;">Serial</span></strong><span style="color: #ff9900;"><span style="color: #000000;">&nbsp;</span></span>mais cette fois ci avec la fonction <strong><span style="color: #ff9900;">print</span>()</strong> qui permet d'envoyer les données souhaitées.</p>
<p>Elle se présente sous cette forme:</p>
<ul>
<li><strong><span style="color: #ff9900;">Serial</span>.<span style="color: #ff9900;">print</span>( <span style="color: #0000ff;">Donnée à afficher</span>); </strong>// Affichage d'une donnée au moniteur série.</li>
</ul>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2206" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/13-Moniteur-serie..png" alt="13-moniteur-serie" width="591" height="38" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/13-Moniteur-serie..png 311w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/13-Moniteur-serie.-300x19.png 300w" sizes="auto, (max-width: 591px) 100vw, 591px" /></p>
<p>La fonction <strong><span style="color: #ff9900;">print</span>()</strong> de <strong><span style="color: #ff9900;">Serial</span> </strong>nous <strong>permet d'afficher deux types de données. </strong>Les numériques et alphabétiques . mais aussi des phrases complètes. Mais pour cela<strong> il nous faudra les différencier.</strong></p>
<p>La différence de ces deux types de données se ferra dans<strong> l'emploie des guillemets "&nbsp; "&nbsp;</strong>dans les parenthèse de la fonction. les guillemets permettent à la fonction <strong><span style="color: #ff9900;">print</span>()</strong> d<strong>'identifier une chaîne de caractères</strong> en d’autres termes une phrase. C'est pour cela que dès lors que nous avons besoins d'afficher une phrase au moniteur il nous faudra<strong> l'encadrer de guillemets </strong>dans les parenthèses de la fonction. Tandis que pour les valeurs numériques brut ou les varaibles cela ne sera pas inutile. Voyez l'exemple ci dessous.</p>
<p><img loading="lazy" decoding="async" class="wp-image-2209 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/14-Moniteur-serie.-e1479074299417.png" alt="14-moniteur-serie" width="478" height="173" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/14-Moniteur-serie.-e1479074299417.png 365w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/11/14-Moniteur-serie.-e1479074299417-300x108.png 300w" sizes="auto, (max-width: 478px) 100vw, 478px" /></p>
<p>L'exemple ci dessus nous donne les base de l'envoie de donnée vers le moniteur.</p>
<h3>&nbsp;<span style="text-decoration: underline;"><strong>Envoyer des données depuis le moniteur.</strong></span></h3>
<p><strong>Le moniteur série ne sert pas seulement à recevoir des données,&nbsp;il peut également en envoyer</strong>. C'est pour cela que nous avons<strong> un bouton de commande "envoyer" avec une zone de saisie de données.</strong></p>
<p style="text-align: justify;">Une autre <strong><span style="color: #000000;">Classe</span></strong> nous sera nécessaire pour l'exploitation du moniteur série et pour l'envoi de<strong> phrases appelées des chaînes de caractères alphabétiques</strong>. C'est la classe<strong><span style="color: #33cccc;"> String</span></strong><em><span style="color: #ff9900;"><span style="color: #000000;"> qui veut dire </span></span><span style="color: #ff9900;"><span style="color: #000000;">"chaîne" en</span></span></em><em><span style="color: #ff9900;"><span style="color: #000000;"> français</span></span></em><span style="color: #ff9900;"><span style="color: #000000;">.</span></span><span style="color: #ff9900;"><span style="color: #000000;"> De même que </span></span><span style="color: #ff9900;"><span style="color: #000000;"><strong><span style="color: #ff9900;">Serial</span></strong> la classe<strong><span style="color: #33cccc;"> String</span></strong> englobe des fonctions particulières, utiles aux traitements des chaînes de caractères. </span></span></p>
<p style="text-align: justify;"><span style="color: #ff9900;"><span style="color: #000000;">Par contre </span></span><strong>pour exploiter la classe <span style="color: #33cccc;">string</span>,</strong> il nous faut<strong><span style="text-decoration: underline;"> lui affecter un dit "<span style="color: #008000; text-decoration: underline;">objet</span>".</span></strong> Plusieurs "<strong><span style="color: #008000;">objets</span></strong>" peuvent être affectés à une classe. On appelle ça <strong>une instanciation</strong>.</p>
<p style="text-align: justify;">Cela se présente de cette manière:<a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-string-objet.png"><img loading="lazy" decoding="async" class="wp-image-1087 aligncenter" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/Mointeur-série-string-objet.png" alt="Mointeur série string objet" width="527" height="37"></a>Par contre les guillemets sont laissés vides pour accueillir une chaîne de caractères (phrases) transmise par le moniteur série.</p>
<p style="text-align: justify;"><strong>"maPhrase"</strong> est notre objet. Vous remarquerez aussi qu<span style="text-decoration: underline;">'il n'est pas utile de placer un point</span> entre l'<strong><span style="color: #008000;">objet</span></strong> et la classe; contrairement à <strong><span style="color: #ff9900;">Serial</span>.</strong></p>
<p style="text-align: justify;">Un <strong><span style="color: #008000;">objet,</span></strong> c'est un peu comme une variable mais pas vraiment. Cet objet contiendra la donnée à exploiter mais ne sera exploitable que par le biais de la <strong><span style="color: #000000;">Classe</span></strong> et de ses fonctions incluses.</p>
<h3 style="text-align: justify;"><span style="text-decoration: underline;">Les fonctions de la classe <strong><span style="color: #33cccc; text-decoration: underline;">String</span></strong>.</span></h3>
<p style="text-align: justify;">Voici ci-dessous les différentes fonctions de <strong><span style="color: #33cccc;">String</span></strong>.</p>
<ul>
<li><strong><span style="color: #ff950e;">trim</span>()</strong> Supprime les espaces dit des «&nbsp;blancs » au début et à la fin d'une chaîne de caractères.</li>
<li><strong><span style="color: #ff950e;">concat</span>()</strong> Rassemble (concatène) deux objets String en un seul dans un nouvel objet String.</li>
<li><strong><span style="color: #ff950e;">compareTo</span></strong><span style="color: #000000;"><strong>()</strong> Compare deux Objets String.</span></li>
<li><strong><span style="color: #ff950e;">toLowerCase</span>()</strong> Retourne en minuscules la chaîne de caractères d'un objet String.</li>
<li><strong><span style="color: #ff950e;">toUpperCase</span>()</strong> Retourne en majuscules la chaîne de caractères d'un objet String.</li>
<li><strong><span style="color: #ff950e;">setCharAt</span>()</strong> Modifie un caractère d'un objet String.</li>
<li><strong><span style="color: #ff9900;">charAt</span></strong><span style="color: #000000;"><strong>()</strong> Retourne à un caractère précis de l'objet String.</span></li>
<li><strong><span style="color: #ff950e;">endsWith</span>()</strong> Contrôle qu'un objet String se termine ou pas avec des caractères d'un autre objet String.</li>
<li><strong><span style="color: #ff950e;">equals</span>()</strong> Contrôle la similarité de deux objets String. En prenant en compte le format.</li>
<li><strong><span style="color: #ff950e;">equalsIgnoreCase</span>()</strong> Compare la similarité de deux objets String sans prendre en compte le format.</li>
<li><strong><span style="color: #ff950e;">getBytes</span>()</strong> Pointe dans un tableau interne les caractères utilisés pour stocker les caractères d'un objet String.</li>
<li><strong><span style="color: #ff950e;">indexOf</span>()</strong> Localise un caractère ou un String dans un autre objet String</li>
<li><strong><span style="color: #ff950e;">lastIndexOf</span>()</strong> Localise un caractère ou un String dans un autre objet String</li>
<li><strong><span style="color: #ff950e;">length</span>()</strong> Renvoie la longueur de la chaîne d'un objet String, en nombre de caractères</li>
<li><strong><span style="color: #ff950e;">replace</span>()</strong> La fonction replace() de la classe String pour permet de remplacer toutes les instances d'un caractère donné par un autre caractère.</li>
<li><strong><span style="color: #ff950e;">startsWith</span>()</strong> Teste si un objet String commence avec les caractères d'un autre objet String.</li>
<li><strong><span style="color: #ff950e;">substring</span>()</strong> Extrait une sous-chaîne d'un objet String.</li>
<li><strong><span style="color: #ff950e;">toCharArray</span>()</strong> Copie les caractères d'un objet String dans un tableau de caractères (char).</li>
</ul>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">FIN.</span></strong></h3>
<p><em>Nous vous invitons à découvrir plus en détail le<strong><span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/moniteur-serie/"> moniteur série</a> </span></span></strong>au travers de nos<strong> projets de mise en pratique. Vous trouverez les codes sources de ce sujet en les <span style="text-decoration: underline;"><span style="color: #3366ff; text-decoration: underline;"><a style="color: #3366ff; text-decoration: underline;" href="https://plaisirarduino.fr/telechargement/">téléchargeant</a>.</span></span></strong></em></p>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;"> MERCI!</span></strong></h3>
<p>Cet article <a href="https://plaisirarduino.fr/le-moniteur-serie/">le moniteur série. Qu&rsquo;est ce que c&rsquo;est ?</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>while / do while + break;  / continue;.</title>
		<link>https://plaisirarduino.fr/la-boucle-while/</link>
		
		<dc:creator><![CDATA[M.D-L]]></dc:creator>
		<pubDate>Wed, 22 Jun 2016 19:13:56 +0000</pubDate>
				<category><![CDATA[Débutant Arduino]]></category>
		<guid isPermaLink="false">https://plaisirarduino.fr/?p=739</guid>

					<description><![CDATA[<p>while( ) { } Ma définition: while en anglais veut dire "tant que" en français . C'est une expression qui signifie "aussi longtemps que" . Le bloc while entre accolades {} s’exécutera tant que sa condition d'exécution est vraie. Soit "true" . Elle est construite en deux parties. Une condition d’exécution &#8230;</p>
<p>Cet article <a href="https://plaisirarduino.fr/la-boucle-while/">while / do while + break;  / continue;.</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3 style="text-align: left;"><strong><span style="color: #808000;">while</span><span style="color: #808000;"><span style="color: #000000;">( ) { }<br />
</span></span></strong></h3>
<p style="text-align: left;"><span style="text-decoration: underline;"><strong><span style="color: #000000; text-decoration: underline;">Ma définition:</span></strong></span> <strong><span style="color: #808000;">while</span></strong> en anglais veut dire "<strong>tant que</strong>" en français . C'est une expression qui signifie "<strong>aussi longtemps que</strong>" . <strong>Le bloc <span style="color: #808000;">while</span> entre accolades {} </strong><strong>s’exécutera tant que</strong> sa <strong>condition d'exécution</strong> est <strong><span style="text-decoration: underline;">vraie</span></strong>. Soit "<strong><span style="color: #33cccc;">true</span></strong><span style="color: #33cccc;"><span style="color: #000000;">" </span></span>.</p>
<p style="text-align: left;"><strong><span style="text-decoration: underline;">Elle est construite en deux parties.</span></strong></p>
<ul>
<li style="text-align: left;"><strong>Une condition d’exécution ()</strong> qui est le déclencheur de la boucle.</li>
<li style="text-align: left;"><strong>Un bloc {} d'actions programmées</strong> à réaliser en boucle.</li>
</ul>
<p><strong><span style="text-decoration: underline;">Se présente sous cette forme.(Exemple)</span></strong></p>
<p><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/while-présentation-5.png"><strong><span style="color: #808000;">while</span></strong> <span style="color: #000000;">( <strong><span style="color: #ff0000;">Condition d’exécution</span></strong> ) { <strong><span style="color: #339966;">Bloc d’actions programmées ;</span></strong>}</span><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1297" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/while-présentation-5.png" alt="while présentation 5" width="597" height="168" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/while-présentation-5.png 597w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/while-présentation-5-300x84.png 300w" sizes="auto, (max-width: 597px) 100vw, 597px" /></a></p>
<p style="text-align: justify;">Prenons l’exemple ci-dessus. Cela nous donne :</p>
<ul>
<li style="text-align: justify;">Si<strong> la condition d'exécution ()</strong> est <span style="text-decoration: underline;"><strong>vraie</strong> "<strong><span style="color: #33cccc; text-decoration: underline;">true</span></strong>" ,</span> soit la <strong><span style="color: #ff0000;">variable de contrôle</span> <span style="color: #ff0000;">"resultat" inférieure à 50</span></strong><span style="color: #ff0000;"><span style="color: #000000;">. </span></span>L'action programmée sera exécutée.</li>
<li style="text-align: justify;"><strong>Le bloc d'actions programmées entre accolades {}:</strong> <span style="color: #008000;">Réalise le calcul</span> et <span style="color: #008000;">affiche le résultat</span> <strong>tant que</strong> la<span style="text-decoration: underline;"> condition d'exécution est vraie</span> "<strong><span style="color: #33cccc;">true</span></strong>" soit égale à "1".<strong><br />
</strong></li>
</ul>
<p style="text-align: justify;"><strong>Lorsque la variable <span style="text-decoration: underline;">"<span style="color: #000000; text-decoration: underline;">resultat</span>"  appelée variable de contrôle</span> </strong>aura une valeur<strong> supérieure à 49, la condition d’exécution deviendra fausse "<span style="color: #33cccc;">false</span>" . L'exécution en boucle se terminera </strong>et ne reprendra que lorsque la condition redeviendra vraie.</p>
<p style="text-align: justify;">Une fois à l'intérieur de la boucle <strong><span style="color: #808000;">while,</span></strong> <strong> il faut pouvoir en sortir</strong>. Il faut donc que la ou <strong>les variables de contrôle</strong> utilisées dans la condition d'exécution <strong>soient manipulées ou changées via une action dans le bloc d'actions programmées</strong>. Sans cela <strong><span style="color: #808000;">while</span></strong> bouclera sans fin.</p>
<p style="text-align: justify;"><strong>Il est toutefois possible d'agir de façon extérieure</strong> au bloc d'actions programmées <strong>en appelant dans la condition d’exécution "fonction"</strong> qui retourne une valeur vraie "<strong><span style="color: #33cccc;">true</span></strong>" ou fausse "<strong><span style="color: #33cccc;">false</span></strong>" après traitement.</p>
<p><span style="text-decoration: underline;">Exemple:</span><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/03/exemple-fonction-while.png"><img loading="lazy" decoding="async" class="wp-image-1055 size-full alignleft" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/03/exemple-fonction-while.png" alt="exemple fonction while" width="182" height="22" /></a> Ci contre nous attendons un <strong>retour de traitement de la fonction</strong> égale à zéro <strong>pour stopper l’exécution</strong> de la boucle <strong><span style="color: #808000;">while</span></strong>.</p>
<h3 style="text-align: left;"><span style="text-decoration: underline;"><strong>NOTE:</strong></span></h3>
<ul>
<li style="text-align: justify;"><strong>La façon<span style="text-decoration: underline;"> locale ou globale</span> dont sera déclarée la variable de contrôle</strong> de la boucle déterminera le traitement de celle-ci et le déroulement de votre programme. Une <strong>variable de contrôle déclarée en local</strong> du programme principal <strong><span style="color: #808000;">loop</span>()</strong> sera initialisée à sa valeur définie lors de chaque passage, ce qui <strong>entraînerait une exécution systématique du bloc </strong><span style="color: #000000;"><strong><span style="color: #808000;">while</span></strong>() <strong>en boucle,</strong> si sa condition est vraie.</span> A l'inverse d'une variable déclarée en global.<strong><br />
</strong></li>
<li style="text-align: justify;">Il faut prendre garde à <span style="text-decoration: underline;"><strong>la manière dont on crée la condition d'exécution</strong></span> du bloc en boucle. L'utilisation d'une variable de type "<strong><span style="color: #33cccc;">float</span></strong>" utilisée avec un opérateur de comparaison " <strong>== "</strong> demanderait une valeur précise pouvant aller jusqu'au dixième près. Il y a risque de bloquer le programme principal dans une boucle sans fin. Dans ce cas là, il est recommandé d'utiliser les opérateurs de comparaison suivants (<strong>=&gt;</strong> ou <strong>&lt;=</strong>).</li>
<li style="text-align: justify;">Utile pour tester ou déboguer un programme; <strong><span style="color: #808000;">while</span>(1);</strong> est parfois utilisé pour stopper un programme à un moment souhaité en le bloquant dans la boucle. Mais  pour effectuer un nouveau cycle programmé cela revient à "<span style="text-decoration: underline;">arracher la prise</span>" par un téléversement ou un re-set de l'Arduino.</li>
</ul>
<h3 style="text-align: left;"><strong><span style="color: #808000;">do</span><span style="color: #000000;">{ }</span><span style="color: #808000;"> while</span><span style="color: #808000;"><span style="color: #000000;">( );</span></span></strong></h3>
<p style="text-align: justify;"><strong><span style="text-decoration: underline;">Ma définition:</span></strong> <strong><span style="color: #808000;">do</span></strong> en anglais veut dire<strong> faire</strong> en français. <strong><span style="color: #808000;">do</span> </strong>est<strong> un bloc </strong>qui est systématiquement <span style="text-decoration: underline;">exécuté au moins une fois et répété en boucle</span><strong> tant que</strong> la <strong>condition d'exécution</strong> <strong><span style="color: #808000;">while,</span></strong> <strong>sera vraie</strong> "<strong><span style="color: #33cccc;">true</span></strong>" .<strong><span style="color: #808000;">while</span></strong> est ici en sortie de bloc.</p>
<p><strong><span style="text-decoration: underline;">Elle est construite en deux parties.</span></strong></p>
<ul>
<li><strong>Un bloc d'actions programmées entre accolades {}</strong> réalisé au moins une fois.</li>
<li><span style="color: #000000;"><strong>Une condition d’exécution</strong></span> qui est cette fois, le déclencheur d'arrêt de la mise en boucle.</li>
</ul>
<p><strong><span style="text-decoration: underline;">Se présente sous cette forme.(Exemple)</span></strong></p>
<p><strong><span style="color: #808000;">do</span>{ <span style="color: #339966;">bloc d'actions programmées ;</span>} <span style="color: #808000;">while</span>(<span style="color: #ff0000;">condition d’exécution</span>) ;</strong><a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/do-while-presentation.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1301" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/do-while-presentation.png" alt="do while presentation" width="541" height="171" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/do-while-presentation.png 541w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/do-while-presentation-300x95.png 300w" sizes="auto, (max-width: 541px) 100vw, 541px" /></a></p>
<p><span style="text-decoration: underline;">Prenons l’exemple ci-dessus. Cela nous donne :</span></p>
<ul>
<li style="text-align: justify;">Exécution systématique du bloc d'actions<strong> programmées <span style="color: #808000;">do</span></strong> . <span style="color: #339966;">Traitement du calcul</span> et <span style="color: #339966;">affichage de la</span> <span style="color: #339966;">valeur de <span style="color: #ff0000;">"resultat"</span> <span style="color: #ff0000;">la variable de contrôle</span></span> de <strong><span style="color: #808000;">while</span><span style="color: #000000;">()</span></strong>.</li>
<li style="text-align: justify;">Contrôle si la<strong> condition d'exécution de</strong> <strong><span style="color: #808000;">while</span></strong> est vraie "<strong><span style="color: #33cccc;">true</span></strong>" . <span style="color: #ff0000;"><span style="color: #000000;">Soit</span> inférieure à 100</span>. <span style="text-decoration: underline;">Réitération en boucle des actions programmées du bloc <strong><span style="color: #808000; text-decoration: underline;">do</span></strong> tant que la condition d’exécution est <strong>vraie</strong> "<strong><span style="color: #33cccc; text-decoration: underline;">true</span></strong>" </span>. Une fois que la condition d'exécution sera <strong>fausse</strong> "<strong><span style="color: #33cccc;">false</span></strong>", la mise en boucle du bloc ne sera plus exécutée mais seulement exécutée une seule fois à chaque lecture du programme principal <strong><span style="color: #808000;">loop</span>()</strong>.</li>
</ul>
<p><span style="text-decoration: underline;"><strong>NOTE</strong>:</span> Ne pas oublier le point virgule "<strong>;</strong>" à la suite de <strong><span style="color: #808000;">while<span style="color: #000000;">()</span></span></strong> quand ce dernier succède au bloc <strong><span style="color: #808000;">do<span style="color: #000000;">{}</span></span>.</strong></p>
<h3><strong><span style="color: #808000;">break</span>;</strong></h3>
<p style="text-align: justify;"><strong><span style="text-decoration: underline;">Ma définition:</span></strong> <strong><span style="color: #808000;">break</span></strong> en anglais signifie <strong>casser ou pause</strong> en français. <strong><span style="color: #808000;">break</span> est une instruction</strong> qui va dans notre cas <strong>stopper la mise en boucle du bloc dans lequel il est intégré et en sortir.</strong></p>
<p><strong><span style="text-decoration: underline;">Se présente sous cette forme.(Exemple)</span></strong></p>
<p><strong><span style="color: #808000;">break</span></strong> <strong>; </strong>//Arrête le bouclage du bloc dans lequel il est placé et en sort.<a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/break1.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1304" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/break1.png" alt="break" width="510" height="236" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/break1.png 510w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/break1-300x139.png 300w" sizes="auto, (max-width: 510px) 100vw, 510px" /></a></p>
<p style="text-align: justify;">Toutes <strong>les instructions antérieures à</strong> <strong><span style="color: #808000;">break</span></strong> <strong>sont exécutées</strong>, le bloc ne sera exécuté qu'une seule fois, <strong><span style="color: #808000;"> break</span></strong> stoppe le bouclage et sort du bloc pour revenir au programme principal. Si la condition d'exécution est toujours vraie à la prochaine exécution de<strong><span style="color: #808000;"> loop</span>()</strong>  les instructions du bloc antérieur à <strong><span style="color: #808000;">break</span></strong> sont tout de même exécutées mais pas celles qui suivront ce dernier.</p>
<p style="text-align: justify;"><strong><span style="text-decoration: underline;">NOTE:</span><br />
</strong></p>
<ol>
<li><strong><span style="color: #808000;">break</span></strong> peut être utilisé avec les blocs <strong><span style="color: #ff9900;">for</span></strong>, <strong><span style="color: #808000;">switch</span></strong><span style="color: #000000;">,</span> <strong><span style="color: #808000;">while</span></strong> et <strong><span style="color: #808000;">do while</span></strong>.</li>
</ol>
<p style="text-align: justify;">Lorsque <strong><span style="color: #808000;">break</span> </strong>se trouve <strong>dans une imbrication de boucle</strong>; il stoppera uniquement les instructions contenues dans le bloc (entre les accolades {}) dans lequel il est intégré.  Le programme poursuivra ensuite dans le bloc suivant.</p>
<h3><strong><span style="color: #808000;">continue</span>;</strong></h3>
<p><strong><span style="text-decoration: underline;">Ma définition:</span> <span style="color: #808000;">continue</span></strong> en anglais veut dire évidement <strong>continuer</strong> en français. <strong><span style="color: #808000;">continue</span> est une instruction</strong> qui va<strong> continuer la réitération d'un bouclage en ignorant les instructions qui suivent son emplacement</strong></p>
<p><strong><span style="text-decoration: underline;">Se présente sous cette forme.(Exemple)</span></strong></p>
<p><strong><span style="color: #808000;">continue</span></strong>; //Ignore les instructions qui vont suivre et reboucler au début.<a href="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/05-continue.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1311" src="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/05-continue.png" alt="05 continue" width="569" height="549" srcset="https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/05-continue.png 569w, https://plaisirarduino.fr/arduino/wp-content/uploads/2016/04/05-continue-300x289.png 300w" sizes="auto, (max-width: 569px) 100vw, 569px" /></a></p>
<p style="text-align: justify;">Dans l'exemple ci-dessus, nous intégrons une <span style="color: #000000;">condition d’exécution </span>pour activer l'instruction<strong><span style="color: #808000;"> continue<span style="color: #000000;">. </span></span></strong><span style="color: #808000;"><span style="color: #000000;">Lorsque celle-ci sera vraie "<strong><span style="color: #33cccc;">true</span></strong>" soit <span style="color: #ff0000;">"resultat" compris entre 50 et 70</span> , <strong><span style="text-decoration: underline;">les instructions suivantes</span> ne seront pas exécutées, c'est-à-dire <span style="color: #339966;">le calcul numéro 2<span style="color: #000000;"> et</span> l'affichage de résultat</span> </strong>. <strong>On rebouclera au début du bloc</strong> pour y refaire notre <strong><span style="color: #339966;">premier calcul</span></strong>.<br />
</span></span></p>
<p style="text-align: justify;"><strong><span style="text-decoration: underline;">NOTE:</span><br />
</strong></p>
<ul>
<li style="text-align: justify;"><strong><span style="color: #808000;">continue</span></strong> peut être utilisé dans les blocs <strong><span style="color: #ff9900;">for</span></strong>, <strong><span style="color: #808000;">while</span></strong> et <strong><span style="color: #808000;">do while</span></strong>.</li>
<li style="text-align: justify;">Pour l'exploiter il est préférable de conditionner son utilisation.</li>
<li style="text-align: justify;">Pour des essais et des contrôles, on peut utiliser <strong><span style="color: #808000;">continue</span></strong> sans conditionnement pour ignorer une portion finale de bloc que l'on ne souhaite pas exécuter en boucle.</li>
</ul>
<h3 style="text-align: center;"><strong><span style="color: #0000ff;">FIN.</span></strong></h3>
<p>Vous connaissez à présent les bases des boucles <strong><span style="color: #808000;">while</span></strong>() et <strong><span style="color: #808000;">do</span></strong>{} <strong><span style="color: #808000;">while</span></strong>(); avec l'utilisation des instructions <strong><span style="color: #808000;">break</span><span style="color: #000000;">; </span></strong><span style="color: #000000;">et</span><strong><span style="color: #808000;"> continue</span></strong><span style="color: #808000;"><span style="color: #000000;"><strong>;</strong>.</span></span></p>
<p><em>Découvrez <strong><span style="color: #808000;"> while </span></strong>/ <strong><span style="color: #808000;">do while</span></strong> / <strong><span style="color: #808000;">break</span></strong> et<strong> <span style="color: #808000;">continue </span></strong><span style="color: #808000;"><span style="color: #000000;">en <span style="color: #0000ff;">téléchargeant</span></span></span><span style="color: #000000;"> les sketchs référents de ce sujet. <strong>Merci</strong>.</span></em><span style="color: #0000ff;"><br />
</span></p>
<p>Cet article <a href="https://plaisirarduino.fr/la-boucle-while/">while / do while + break;  / continue;.</a> est apparu en premier sur <a href="https://plaisirarduino.fr">PlaisirArduino</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Mise en cache de page à l’aide de Disk: Enhanced 
Minified using Disk
Mise en cache de la base de données de 54/167 requêtes en 0.062 secondes utilisant Disk

Served from: plaisirarduino.fr @ 2026-05-12 07:10:30 by W3 Total Cache
-->