Différences entre versions de « Afficheur LCD-Code Arduino »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
(Page créée avec « {{afficheur-lcd-nav}} xxx <small>Créer par [http://learn.adafruit.com/users/srmonk Simon Monk] pour AdaFruit</small> {{ADF-Accord}} {{MCH-Accord}} »)
 
Ligne 1 : Ligne 1 :
 
{{afficheur-lcd-nav}}
 
{{afficheur-lcd-nav}}
  
xxx
+
The Arduino IDE includes an example of using the LCD library which we will use. You can find this on the File menu under Examples → Liquid Crystal → HelloWorld.
 +
 
 +
This example uses different pins to the ones we use, so find the line of code below:
 +
 
 +
<nowiki>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<nowiki>
 +
 
 +
and change it to be:
 +
 
 +
<nowiki>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);</nowiki>
 +
 
 +
Upload the code to your Arduino board and you should see the message 'hello, world' displayed, followed by a number that counts up from zero.
 +
 
 +
The first thing of note in the sketch is the line:
 +
 
 +
<nowiki>#include <LiquidCrystal.h></nowiki>
 +
 
 +
This tells Arduino that we wish to use the Liquid Crystal library.
 +
 
 +
Next we have the line that we had to modify. This defines which pins of the Arduino are to be connected to which pins of the display.
 +
 
 +
<nowiki>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);</nowiki>
 +
 
 +
The arguments to this are as follows:
 +
 
 +
{| class="wikitable" border="1"
 +
| align="center" style="background:#f0f0f0;"|'''Display Pin Name'''
 +
| align="center" style="background:#f0f0f0;"|'''Display Pin Number'''
 +
| align="center" style="background:#f0f0f0;"|'''Arduino Pin (in this example)'''
 +
|-
 +
| RS ||4 ||7
 +
|-
 +
| E ||6 ||8
 +
|-
 +
| D4 ||11 ||9
 +
|-
 +
| D5 ||12 ||10
 +
|-
 +
| D6 ||13 ||11
 +
|-
 +
| D7 ||14 ||12
 +
|}
 +
 
 +
In the 'setup' function, we have two commands:
 +
 
 +
<nowiki>lcd.begin(16, 2);
 +
lcd.print("hello, world!");</nowiki>
 +
 
 +
The first tells the Liquid Crystal library how many columns and rows the display has. The second line displays the message that we see on the first line of the screen.
 +
 
 +
In the 'loop' function, we aso have two commands:
 +
 
 +
<nowiki>lcd.setCursor(0, 1);
 +
lcd.print(millis()/1000);</nowiki>
 +
 
 +
The first sets the cursor position (where the next text will appear) to column 0 or row 1. Both column and row numbers start at 0 rather than 1.
 +
 
 +
The second line displays the number of milliseconds since the Arduino was reset.
 +
 
  
 
<small>Créer par [http://learn.adafruit.com/users/srmonk Simon Monk] pour AdaFruit</small>
 
<small>Créer par [http://learn.adafruit.com/users/srmonk Simon Monk] pour AdaFruit</small>

Version du 1 janvier 2013 à 15:05

The Arduino IDE includes an example of using the LCD library which we will use. You can find this on the File menu under Examples → Liquid Crystal → HelloWorld.

This example uses different pins to the ones we use, so find the line of code below:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<nowiki>

and change it to be:

 <nowiki>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

Upload the code to your Arduino board and you should see the message 'hello, world' displayed, followed by a number that counts up from zero.

The first thing of note in the sketch is the line:

#include <LiquidCrystal.h>

This tells Arduino that we wish to use the Liquid Crystal library.

Next we have the line that we had to modify. This defines which pins of the Arduino are to be connected to which pins of the display.

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

The arguments to this are as follows:

Display Pin Name Display Pin Number Arduino Pin (in this example)
RS 4 7
E 6 8
D4 11 9
D5 12 10
D6 13 11
D7 14 12

In the 'setup' function, we have two commands:

lcd.begin(16, 2);
lcd.print("hello, world!");

The first tells the Liquid Crystal library how many columns and rows the display has. The second line displays the message that we see on the first line of the screen.

In the 'loop' function, we aso have two commands:

lcd.setCursor(0, 1);
lcd.print(millis()/1000);

The first sets the cursor position (where the next text will appear) to column 0 or row 1. Both column and row numbers start at 0 rather than 1.

The second line displays the number of milliseconds since the Arduino was reset.


Créer par Simon Monk pour AdaFruit

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.