{"id":6502,"date":"2023-09-14T15:30:01","date_gmt":"2023-09-14T13:30:01","guid":{"rendered":"https:\/\/www.ardpylab.fr\/?page_id=6502"},"modified":"2023-09-15T10:33:12","modified_gmt":"2023-09-15T08:33:12","slug":"des-sketchs-a-ajouter-a-ardpylog-suite-7","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=6502","title":{"rendered":"Des sketchs \u00e0 ajouter \u00e0 ArdPyLog (suite)"},"content":{"rendered":"\n<p><strong style=\"color: inherit; font-size: 1.25em;\"><br \/>7. <a href=\"https:\/\/www.ardpylab.fr\/downloads\/ardpylog\/EcranLCD2.zip\"><span style=\"text-decoration: underline; color: #3366ff;\">Ecran LCD 2<\/span><\/a><\/strong><span style=\"color: inherit; font-size: 1.25em; font-weight: 600;\"> (Incr\u00e9menter un compteur &#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>\u00a0<\/p>\n<p>L&rsquo;objectif de cette activit\u00e9 est d\u2019incr\u00e9menter un compteur en appuyant sur un bouton poussoir puis d\u2019afficher sa valeur sur un \u00e9cran LCD. Un appui prolong\u00e9 sur le bouton poussoir remet le compteur \u00e0 z\u00e9ro.<\/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>\u00a0<\/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 &lt;LiquidCrystal.h&gt;<\/p>\n<p>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<\/p>\n<p>const int switchPin = 6;<\/p>\n<p>int switchState = 0;<\/p>\n<p>int prevSwitchState = 0;<\/p>\n<p>int comptBtn=0;<br \/>unsigned long startTime = 0;<br \/>unsigned long DeltaTime = 0;<\/p>\n<p><br \/>void setup() {<br \/><br \/>lcd.begin(16, 2);<br \/><br \/>pinMode(switchPin,INPUT);<br \/><br \/>lcd.print(\u00ab\u00a0Appuyez sur le\u00a0\u00bb);<br \/>lcd.setCursor(0, 1);<br \/>lcd.print(\u00ab\u00a0bouton poussoir\u00a0\u00bb);<br \/>}<\/p>\n<p>void loop() {<br \/>switchState = digitalRead(switchPin);<\/p>\n<p>if (switchState != prevSwitchState) {<br \/><br \/>if (switchState == HIGH) {<br \/>startTime = millis();<br \/>comptBtn = comptBtn +1;<br \/>lcd.clear();<br \/>lcd.setCursor(0, 0);<br \/>lcd.print(\u00ab\u00a0NUMERO:\u00a0\u00bb);<br \/>lcd.setCursor(0, 1);<br \/>lcd.print(comptBtn); <br \/>}<br \/><br \/>}<br \/>if ((switchState == HIGH) &amp;&amp; (prevSwitchState == HIGH)) {<br \/>DeltaTime = millis() &#8211; startTime;<br \/>if (DeltaTime &gt; 500) {<br \/>comptBtn = 0;<br \/>lcd.clear();<br \/>lcd.setCursor(0, 0);<br \/>lcd.print(\u00ab\u00a0Appuyez sur le\u00a0\u00bb);<br \/>lcd.setCursor(0, 1);<br \/>lcd.print(\u00ab\u00a0bouton poussoir\u00a0\u00bb);<br \/>}<br \/>}<br \/>prevSwitchState = switchState;<br \/>}<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/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>\u00a0<\/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 comptBtn<\/strong> (variable nombre entier correspondant \u00e0 la valeur du compteur qui doit \u00eatre affich\u00e9e)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>unsigned long startTime = 0<\/strong> (variable nombre entier long pour stocker l\u2019heure d\u2019appui sur le bouton poussoir)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>unsigned long DeltaTime = 0<\/strong> (variable nombre entier long pour stocker la dur\u00e9e d\u2019appui sur le bouton poussoir)<\/p>\n<p>\u00a0<\/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>\u00a0<\/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, le compteur est incr\u00e9ment\u00e9,<\/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-6505\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD2_1-300x270.jpg\" alt=\"\" width=\"300\" height=\"270\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD2_1-300x270.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/EcranLCD2_1.jpg 670w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u2013&gt; <strong>Si le bouton poussoir est maintenu appuy\u00e9, le compteur est remis \u00e0 z\u00e9ro.<\/strong><\/p>\n<p>\u00a0<\/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=6486\"><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=6510\"><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>7. Ecran LCD 2 (Incr\u00e9menter un compteur &#8211; Cat\u00e9gorie: Divers) \u00a0 L&rsquo;objectif de cette activit\u00e9 est d\u2019incr\u00e9menter un compteur en appuyant sur un bouton poussoir puis d\u2019afficher sa valeur sur un \u00e9cran LCD. Un appui prolong\u00e9 sur le bouton poussoir remet le compteur \u00e0 z\u00e9ro. L\u2019\u00e9cran \u00e0 cristaux liquides utilis\u00e9 comporte deux rang\u00e9es de 16 [&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-6502","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6502","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=6502"}],"version-history":[{"count":6,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6502\/revisions"}],"predecessor-version":[{"id":6549,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6502\/revisions\/6549"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}