{"id":6510,"date":"2023-09-14T16:06:05","date_gmt":"2023-09-14T14:06:05","guid":{"rendered":"https:\/\/www.ardpylab.fr\/?page_id=6510"},"modified":"2023-09-14T16:41:00","modified_gmt":"2023-09-14T14:41:00","slug":"des-sketchs-a-ajouter-a-ardpylog-suite-8","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=6510","title":{"rendered":"Des sketchs \u00e0 ajouter \u00e0 ArdPyLog (suite)"},"content":{"rendered":"\n<p><strong style=\"color: inherit; font-size: 1.25em;\"><br>8. <a href=\"https:\/\/www.ardpylab.fr\/downloads\/ardpylog\/Generateur.zip\"><span style=\"text-decoration: underline; color: #3366ff;\">G\u00e9n\u00e9rateur<\/span><\/a><\/strong><span style=\"color: inherit; font-size: 1.25em; font-weight: 600;\"> (R\u00e9alisation d\u2019un g\u00e9n\u00e9rateur 0-5 V &#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\/Generateur.jpg\" alt=\"\" class=\"wp-image-6511\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur.jpg 935w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur-300x181.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur-768x464.jpg 768w\" sizes=\"auto, (max-width: 935px) 100vw, 935px\" \/><\/figure><\/div>\n\n\n\n<p>&nbsp;<\/p>\n<p>L\u2019objectif de l\u2019activit\u00e9 est de r\u00e9aliser un g\u00e9n\u00e9rateur 0-5 V pour, par exemple, alimenter une DEL.<\/p>\n<p>Le bouton poussoir permet d\u2019allumer ou d\u2019\u00e9teindre le g\u00e9n\u00e9rateur. La valeur de la tension d\u00e9livr\u00e9e entre la sortie 9 (sortie PWM) et la masse de l\u2019Arduino Uno est r\u00e9gl\u00e9e par le premier potentiom\u00e8tre. La valeur de la tension est affich\u00e9e sur un \u00e9cran LCD.<\/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 deuxi\u00e8me 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>const int switchPin = 6;<br>int const PotPin=A0;<br>int const PinTension=9;<br>int PotVal=0;<br>int OldPotVal=0;<br>float Tension=0.00;<br>int switchState = 0;<br>int prevSwitchState = 0;<br>int state=0;<\/p>\n<p>#include &lt;LiquidCrystal.h&gt;<\/p>\n<p>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<\/p>\n<p><br>void setup() {<br>pinMode(PinTension,OUTPUT);<br>pinMode(switchPin,INPUT);<br>lcd.begin(16, 2);<br>Serial.begin(9600);<\/p>\n<p>}<\/p>\n<p>void loop() {<\/p>\n<p>switchState = digitalRead(switchPin);<\/p>\n<p>if ((switchState == HIGH)&amp;&amp;(prevSwitchState == LOW)) {<br>state=1-state;<br>delay(10);<br>}<br>else {<br>if ((switchState == LOW)&amp;&amp;(prevSwitchState == HIGH)) {<br>delay(10);<br>}<br>}<br>prevSwitchState = switchState;<br><br>if (state==1) {<\/p>\n<p>PotVal=analogRead(PotPin);<br>analogWrite(PinTension,PotVal\/4);<\/p>\n<p>if (PotVal != OldPotVal) {<br>Tension=PotVal*5.00\/1023;<br>lcd.clear();<br>lcd.setCursor(0, 0);<br>lcd.print(\u00ab\u00a0Tension (V):\u00a0\u00bb);<br>lcd.setCursor(0, 1);<br>lcd.print(Tension);<br>Serial.println(Tension);<br>delay(10);<br>}<\/p>\n<p>OldPotVal=PotVal;<\/p>\n<p>}<br>else {<br>analogWrite(PinTension,0); <br>lcd.clear();<br>} <br><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 state=0<\/strong> (variable nombre entier correspondant \u00e0 l\u2019action \u00e0 effectuer)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int const PotPin=A0<\/strong> (constante nombre entier correspondant \u00e0 la broche du premier potentiom\u00e8tre)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int const PinTension=9<\/strong> (constante nombre entier correspondant \u00e0 la borne + du g\u00e9n\u00e9rateur)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int PotVal=0<\/strong> (variable nombre entier pour stocker la valeur du potentiel de la broche du premier potentiom\u00e8tre)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>int OldPotVal=0<\/strong> (variable nombre entier pour stocker l\u2019ancienne valeur du potentiel de la broche du premier potentiom\u00e8tre)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>float Tension=0.00<\/strong> (variable nombre d\u00e9cimal pour stocker la valeur du potentiel en V d\u00e9livr\u00e9 sur la broche correspondant \u00e0 la borne + du g\u00e9n\u00e9rateur)<\/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>Initialisation de la borne + du g\u00e9n\u00e9rateur en sortie,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">. <strong>Initialisation de la liaison s\u00e9rie \u00e0 un d\u00e9bit de 9600 bauds.<\/strong><\/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>Mise \u00e0 jour de la variable \u00ab state \u00bb si changement de la valeur du bouton poussoir,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Mise en route ou arr\u00eat du g\u00e9n\u00e9rateur en fonction de la variable \u00ab state \u00bb,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Lecture de la valeur du potentiel de la broche du premier potentiom\u00e8tre,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Application de cette valeur de potentiel sur la broche correspondant \u00e0 la borne + du g\u00e9n\u00e9rateur,<\/strong><\/p>\n<p style=\"padding-left: 40px;\">\u2013&gt; <strong>Conversion en V de la valeur du potentiel de la broche du premier potentiom\u00e8tre et affichage de cette valeur sur l\u2019\u00e9cran LCD et le moniteur s\u00e9rie, si celle-ci a chang\u00e9e.<\/strong><\/p>\n<p>&nbsp;<\/p>\n\n\n<div  class=\"grids-section grids-is-stretch\" 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:2;--_gs-rows:1\"><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\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"808\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_1-1024x808.jpg\" alt=\"\" class=\"wp-image-6512\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_1-1024x808.jpg 1024w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_1-300x237.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_1-768x606.jpg 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_1.jpg 1142w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:2\/3;--_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\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"809\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_2-1024x809.jpg\" alt=\"\" class=\"wp-image-6513\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_2-1024x809.jpg 1024w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_2-300x237.jpg 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_2-768x607.jpg 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2023\/09\/Generateur_2.jpg 1172w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div>\n<\/div><\/div>\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=6502\"><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=6525\"><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>8. G\u00e9n\u00e9rateur (R\u00e9alisation d\u2019un g\u00e9n\u00e9rateur 0-5 V &#8211; Cat\u00e9gorie: Divers) &nbsp; L\u2019objectif de l\u2019activit\u00e9 est de r\u00e9aliser un g\u00e9n\u00e9rateur 0-5 V pour, par exemple, alimenter une DEL. Le bouton poussoir permet d\u2019allumer ou d\u2019\u00e9teindre le g\u00e9n\u00e9rateur. La valeur de la tension d\u00e9livr\u00e9e entre la sortie 9 (sortie PWM) et la masse de l\u2019Arduino Uno est [&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-6510","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6510","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=6510"}],"version-history":[{"count":6,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6510\/revisions"}],"predecessor-version":[{"id":6534,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/6510\/revisions\/6534"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}