{"id":6486,"date":"2023-09-14T15:01:23","date_gmt":"2023-09-14T13:01:23","guid":{"rendered":"https:\/\/www.ardpylab.fr\/?page_id=6486"},"modified":"2023-09-14T15:42:18","modified_gmt":"2023-09-14T13:42:18","slug":"des-sketchs-a-ajouter-a-ardpylog-suite-6","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=6486","title":{"rendered":"Des sketchs \u00e0 ajouter \u00e0 ArdPyLog (suite)"},"content":{"rendered":"\n<p><strong style=\"color: inherit; font-size: 1.25em;\"><br>6. <a href=\"https:\/\/www.ardpylab.fr\/downloads\/ardpylog\/EcranLCD.zip\"><span style=\"text-decoration: underline; color: #3366ff;\">Ecran LCD<\/span><\/a><\/strong><span style=\"color: inherit; font-size: 1.25em; font-weight: 600;\"> (Afficher un chiffre sur un \u00e9cran LCD&nbsp;&#8211; Cat\u00e9gorie: <\/span><span style=\"color: #3366ff;\"><strong style=\"font-size: 1.25em;\">Divers<\/strong><\/span><span style=\"color: inherit; font-size: 1.25em; font-weight: 600;\">)<br><br><\/span><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"935\" height=\"565\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD.jpg\" alt=\"\" class=\"wp-image-6489\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD.jpg 935w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD-300x181.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD-768x464.jpg 768w\" sizes=\"auto, (max-width: 935px) 100vw, 935px\" \/><\/figure><\/div>\n\n\n\n<p>&nbsp;<\/p>\n<p>L&rsquo;objectif de cette activit\u00e9 est d\u2019afficher un chiffre choisi au hasard sur un \u00e9cran LCD apr\u00e8s un appui sur un bouton poussoir.<\/p>\n<p>L\u2019\u00e9cran \u00e0 cristaux liquides utilis\u00e9 comporte deux rang\u00e9es de 16 caract\u00e8res, d\u2019o\u00f9 son nom de LCD 1602 et le potentiom\u00e8tre du montage permet de r\u00e9gler sa luminosit\u00e9.<\/p>\n<p>Le code de l&rsquo;activit\u00e9 n\u00e9cessite l&rsquo;installation au pr\u00e9alable de la librairie \u00a0\u00bb LiquidCrystal \u00a0\u00bb d\u2019Adafruit.<br>Afin d\u2019ajouter une librairie \u00e0 l\u2019IDE Arduino, il faut aller dans le menu \u00ab Outils -&gt;G\u00e9rer les biblioth\u00e8ques \u00bb :<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-6490\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_1-300x213.jpg\" alt=\"\" width=\"603\" height=\"428\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_1-300x213.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_1-768x546.jpg 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_1.jpg 985w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>Il suffit ensuite de rechercher et d\u2019ajouter la librairie \u00a0\u00bb LiquidCrystal \u00a0\u00bb d\u2019Adafruit:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-6491\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_2-300x170.jpg\" alt=\"\" width=\"594\" height=\"337\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_2-300x170.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_2-768x434.jpg 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_2.jpg 782w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">Le programme<\/span><\/p>\n<p>Voici le code de l\u2019activit\u00e9 :<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 100%; padding-left: 40px;\">\n<p>\/\/ include the library code:<br>#include &lt;LiquidCrystal.h&gt;<\/p>\n<p>\/\/ initialize the library with the numbers of the interface pins<br>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<\/p>\n<p>\/\/ set up a constant for the switchPin<br>const int switchPin = 6;<\/p>\n<p>\/\/ variable to hold the value of the switchPin<br>int switchState = 0;<\/p>\n<p>\/\/ variable to hold previous value of the switchpin<br>int prevSwitchState = 0;<\/p>\n<p>\/\/ a variable to choose which reply on the LCD<br>int reply;<\/p>\n<p>void setup() {<br>\/\/ set up the number of columns and rows on the LCD <br>lcd.begin(16, 2);<br><br>\/\/ set up the switch pin as an input<br>pinMode(switchPin,INPUT);<br><br>\/\/ Print a message to the LCD.<br>lcd.print(\u00ab\u00a0Appuyez sur le\u00a0\u00bb);<br>\/\/ set the cursor to column 0, line 1<br>\/\/ line 1 is the second row, since counting begins with 0<br>lcd.setCursor(0, 1);<br>\/\/ print to the second line<br>lcd.print(\u00ab\u00a0bouton poussoir\u00a0\u00bb);<br>}<\/p>\n<p>void loop() {<br>\/\/ check the status of the switch<br>switchState = digitalRead(switchPin);<\/p>\n<p>\/\/ compare the switchState to its previous state<br>if (switchState != prevSwitchState) {<br><br>if (switchState == HIGH) {<br>\/\/ randomly chose a reply<br>reply = random(10);<br>\/\/ clean up the screen before printing a new reply<br>lcd.clear();<br>\/\/ set the cursor to column 0, line 0 <br>lcd.setCursor(0, 0);<br>\/\/ print some text<br>lcd.print(\u00ab\u00a0Chiffre:\u00a0\u00bb);<br>\/\/ move the cursor to the second line<br>lcd.setCursor(0, 1);<\/p>\n<p><br>switch(reply){<br>case 0:<br>lcd.print(\u00ab\u00a0Zero\u00a0\u00bb);<br>break;<\/p>\n<p>case 1:<br>lcd.print(\u00ab\u00a0Un\u00a0\u00bb);<br>break;<\/p>\n<p>case 2:<br>lcd.print(\u00ab\u00a0Deux\u00a0\u00bb);<br>break;<\/p>\n<p>case 3:<br>lcd.print(\u00ab\u00a0Trois\u00a0\u00bb);<br>break;<\/p>\n<p>case 4:<br>lcd.print(\u00ab\u00a0Quatre\u00a0\u00bb);<br>break;<\/p>\n<p>case 5:<br>lcd.print(\u00ab\u00a0Cinq\u00a0\u00bb);<br>break;<\/p>\n<p>case 6:<br>lcd.print(\u00ab\u00a0Six\u00a0\u00bb);<br>break;<\/p>\n<p>case 7:<br>lcd.print(\u00ab\u00a0Sept\u00a0\u00bb);<br>break;<\/p>\n<p>case 8:<br>lcd.print(\u00ab\u00a0Huit\u00a0\u00bb);<br>break;<\/p>\n<p>case 9:<br>lcd.print(\u00ab\u00a0Neuf\u00a0\u00bb);<br>break;<br>}<br>}<br>}<br>\/\/ save the current switch state as the last state <br>prevSwitchState = switchState;<br>}<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\">D\u00e9roulement du programme<\/span> :<\/p>\n<p>\u2013 1. Insertion des biblioth\u00e8ques :<\/p>\n<p style=\"padding-left: 40px;\">. <strong>Insertion de la librairie \u00a0\u00bb LiquidCrystal \u00a0\u00bb d\u2019Adafruit<\/strong><\/p>\n<p style=\"padding-left: 40px;\">. <strong>Initialisation de la librairie avec les broches utilis\u00e9es pour l\u2019\u00e9cran LCD<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>\u2013 2. D\u00e9claration des constantes et variables :<\/p>\n<p style=\"padding-left: 40px;\">. <strong>const int switchPin = 6<\/strong> (constante nombre entier correspondant \u00e0 la broche du bouton poussoir)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int switchState = 0<\/strong> (variable nombre entier pour stocker la valeur du potentiel de la broche du bouton poussoir)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int prevSwitchState = 0<\/strong> (variable nombre entier pour stocker l\u2019ancienne valeur du potentiel de la broche du bouton poussoir)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int reply<\/strong> (variable nombre entier correspondant au chiffre qui doit \u00eatre affich\u00e9)<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013 3. Initialisation des entr\u00e9es et sorties :<\/p>\n<p style=\"padding-left: 40px;\">. <strong>Initialisation du nombre de lignes et de colonnes de l\u2019\u00e9cran LCD,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">. <strong>Initialisation de la broche du bouton poussoir en entr\u00e9e,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">. <strong>Affichage de la consigne \u00ab Appuyer sur le bouton poussoir \u00bb sur l\u2019\u00e9cran LCD.<\/strong><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6494\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_3-300x250.jpg\" alt=\"\" width=\"300\" height=\"250\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_3-300x250.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_3.jpg 676w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u2013 4. Fonction principale en boucle :<\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Lecture de la valeur de la broche du bouton poussoir,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Si le bouton poussoir est appuy\u00e9, un chiffre est tir\u00e9 au sort,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Affichage du chiffre sur l\u2019\u00e9cran LCD.<\/strong><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-6495\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_4-300x257.jpg\" alt=\"\" width=\"300\" height=\"257\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_4-300x257.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD_4.jpg 654w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n\n\n<div  class=\"grids-section grids-is-advanced\" style=\"--_gs-gap-desktop:0px 0px;--_gs-m-desktop:0 0 0 0;--_gs-p-desktop:0 0 0 0;--_gs-bg-desktop:transparent none;--_gs-bg-xp-desktop:0px;--_gs-zi-desktop:auto;--_gs-d-desktop:block;--_gs-mw-desktop:calc(100% - 0 - 0);--_gs-gap-tablet:0px 0px;--_gs-m-tablet:0 0 0 0;--_gs-p-tablet:0 0 0 0;--_gs-bg-tablet:transparent none;--_gs-bg-xp-tablet:0px;--_gs-zi-tablet:auto;--_gs-d-tablet:block;--_gs-mw-tablet:calc(100% - 0 - 0);--_gs-gap-mobile:0px 0px;--_gs-m-mobile:0 0 0 0;--_gs-p-mobile:0 0 0 0;--_gs-bg-mobile:transparent none;--_gs-bg-xp-mobile:0px;--_gs-zi-mobile:auto;--_gs-d-mobile:block;--_gs-mw-mobile:calc(100% - 0 - 0);--_gs-columns:12;--_gs-rows:6\"><div class=\"grids-s-w_i\">\n<div class=\"grids-area\" style=\"--_ga-column:1\/2;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=6462\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/moins.jpg\" alt=\"\" class=\"wp-image-107\" width=\"44\" height=\"24\"\/><\/a><\/figure>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:12\/13;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=6502\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/plus.jpg\" alt=\"\" class=\"wp-image-106\"\/><\/a><\/figure>\n\n<\/div>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>6. Ecran LCD (Afficher un chiffre sur un \u00e9cran LCD&nbsp;&#8211; Cat\u00e9gorie: Divers) &nbsp; L&rsquo;objectif de cette activit\u00e9 est d\u2019afficher un chiffre choisi au hasard sur un \u00e9cran LCD apr\u00e8s un appui sur un bouton poussoir. L\u2019\u00e9cran \u00e0 cristaux liquides utilis\u00e9 comporte deux rang\u00e9es de 16 caract\u00e8res, d\u2019o\u00f9 son nom de LCD 1602 et le potentiom\u00e8tre [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6486","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6486"}],"version-history":[{"count":7,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6486\/revisions"}],"predecessor-version":[{"id":6507,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6486\/revisions\/6507"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}