Modifications

Sauter à la navigation Sauter à la recherche
57 octets ajoutés ,  31 décembre 2016 à 13:13
Ligne 64 : Ligne 64 :     
== Utiliser le code de la bibliothèque ==
 
== Utiliser le code de la bibliothèque ==
Look at the contents of the char_lcd_plate.py file to see the basic usage of the character LCD plate class. The basic usage is to import the library and create an instance of the Adafruit_CharLCDPlate class. The char LCD plate class is smart enough to know how to talk to the character LCD plate without any configuration or parameters.
+
Jetez un petit coup d'oeil au contenu du fichier '''char_lcd_plate.py''' pour voir l'usage de la classe LCD. L'utilisation de base se résume à importer la bibliothèque et créer une instance de la classe '''Adafruit_CharLCDPlate''' . La classe est suffisamment intelligente pour savoir comment dialoguer avec l'afficheur LCD dans avoir besoin de configuration ou parametres complémentaires.
   −
Once you have an instance of the Adafruit_CharLCDPlate class there are a few functions you can call to interact with the display:
+
Une fois l'instance de la classe '''Adafruit_CharLCDPlate''' créée, il y a quelques fonctions utiles pour interagir avec l'afficheur:
   −
    message(text)
+
message(text)
        Print the provided string message to the display. The text string can include linebreak characters ('\n') and will move to the next line when found in the string.
  −
    clear()
  −
        Clear the display and reset the position of message printing to the first column and first line.
  −
    set_color(red, green, blue)
  −
        Set the color of the red, green, and blue backlight LEDs. Each color value should be a 1 for on or 0 for off. For example to set a red backlight call set_color(1,0,0) or to set a purple color call set_color(1,0,1).
     −
You can find a more detailed write-up of the library in this character LCD guide (see the Usage and Raspberry Pi Char LCD Plate pages).
+
Affiche le texte sur l'afficheur. La chaine de caractère peut inclure un retour à la ligne ('\n'). L'afficheur LCD déplacera le curseur du LCD à la ligne suivante lorsque ce caractère est rencontré.
 +
 
 +
clear()
 +
 
 +
Efface l'écran et réinitialise la position du curseur en haut à gauche (emplacement où démarrera l'affichage du prochain message).
 +
 
 +
set_color(red, green, blue)
 +
 
 +
Fixe l'état du rétro-éclairage pour les couleurs rouge (''red''), verte (''green'') et bleue (''blue''). Chaque couleur peut recevoir une valeur 1 pour allumer la LED (et 0 pour l'éteindre).
 +
 
 +
Par exemple, pour afficher un rétro-éclairage rouge, il faut appeler {{fname|set_color(1,0,0)}} ou en pourpre il faut appeler {{fname|set_color(1,0,1)}} .
 +
 
 +
Vous trouverez You can find a more detailed write-up of the library in this character LCD guide (see the Usage and Raspberry Pi Char LCD Plate pages).
    
<hr />
 
<hr />
   −
Interfacer un code d'exemple avec python est très simple!
+
The first difference is that you create and instance of the Adafruit_CharLCDPlate class. You don't need to pass any parameters in to this class' constructor/init function because it is preconfigured for the LCD plate.
   −
Voici quelques informations qui vous permettrons de démarrer rapidement votre propre projet.  
+
<syntaxhighlight lang="python">
 +
# Initialize the LCD using the pins
 +
lcd = LCD.Adafruit_CharLCDPlate()
 +
</syntaxhighlight>
   −
Dans le dossier Adafruit_CharLCDPlate vous trouverez le script Python '''LCDtest.py'''. Vous pouvez dupliquer ce programme pour commencer le vôtre.
+
The second difference is that the '''Adafruit_CharLCDPlate''' adds a function to test if a button is pressed. Notice how the is_pressed function is called for each button, and if it returns True then the button press is detected.
   −
Ce script '''LCDtest.py''' effectue tout une série d'opérations. La plus importante étant d'importer tous les sous-modules nécessaire.  
+
For example to check if the select button is pressed you can call {{fname|is_presssed(LCD.SELECT)}}, or to check if the right button is pressed you can call {{fname|is_pressed(LCD.RIGHT)}}.  
   −
Vous aurez besoin des fichiers '''Adafruit_I2C.py''', '''Adafruit_MCP230xx.py''' et '''Adafruit_CharLCDPlate.py''', tous localisés dans le même répertoire. Copiez les dans votre destination finale.
+
<syntaxhighlight lang="python">
 +
# Make list of button value, text, and backlight color.
 +
buttons = ( (LCD.SELECT, 'Select', (1,1,1)),
 +
            (LCD.LEFT,  'Left' , (1,0,0)),
 +
            (LCD.UP,     'Up'   , (0,0,1)),
 +
            (LCD.DOWN,  'Down' , (0,1,0)),
 +
            (LCD.RIGHT,  'Right' , (1,0,1)) )
   −
Ensuite, on initialise la platine par '''lcd = Adafruit_CharLCDPlate()''' - cela crée un 'objet' lcd, entame la communication avec la platine, initialise le LCD et les boutons. N'oublier pas de placer la valeur du paramètre busnum (comme dans la section précédente).
+
print 'Press Ctrl-C to quit.'
 +
while True:
 +
# Loop through each button and check if it is pressed.
 +
for button in buttons:
 +
if lcd.is_pressed(button[0]):
 +
# Button is pressed, change the message and backlight.
 +
lcd.clear()
 +
lcd.message(button[1])
 +
lcd.set_color(button[2][0], button[2][1], button[2][2])
 +
</syntaxhighlight>
   −
Après l'initialisation, vous pouvez effacer l'afficheur à l'aide de '''lcd.clear()''' et écrire du texte avec '''lcd.message("le texte doit etre ici")'''.
+
One final thing to note, just like using an MCP230xx IO extender the character LCD plate does not support PWM control of the backlight LEDs!
   −
N'oubliez pas qu'il y a uniquement 16 caractères par ligne et qu'il n'y a pas de de retour à la ligne automatiquement.
+
That's all there is to using the character LCD plate with the character LCD Python library!
   −
Pour insérer retour à la ligne (le caractère "''newline''" comme dise les anglais), il faut utilisez le caractère spécial '\n' dans votre chaine de caractère. Voici un exemple :  '''lcd.message("Adafruit RGB LCD\nPlate w/Keypad!")'''.
+
<hr />
 
  −
Ensuite, vous pouvez gérer le rétroéclairage avec  '''lcd.backlight(lcd.NOM_DE_LA_COULEUR_EN_ANGLAIS)''' où '''NOM_DE_LA_COULEUR_EN_ANGLAIS''' est remplacé par:
  −
* RED pour rouge
  −
* YELLOW pour jaune
  −
* GREEN pour vert
  −
* TEAL pour vert-bleuâtre
  −
* BLUE pour bleu
  −
* VIOLET pour violet.
     −
Ceci n'est valable que pour les afficheur LCD RGB. Pour les afficheurs LCD  monochromes, utiliser seulement ON (allumé) et OFF (éteint).
      
Finalement, vous pouvez interroger la platine pour savoir quel bouton a été pressé à l'aide de '''buttonPressed(lcd.NOM_DU_BOUTON_EN_ANGLAIS)''' où NOM_DU_BOUTON_EN_ANGLAIS est:
 
Finalement, vous pouvez interroger la platine pour savoir quel bouton a été pressé à l'aide de '''buttonPressed(lcd.NOM_DU_BOUTON_EN_ANGLAIS)''' où NOM_DU_BOUTON_EN_ANGLAIS est:
29 917

modifications

Menu de navigation