Ligne 64 : |
Ligne 64 : |
| | | |
| == Utiliser le code de la bibliothèque == | | == Utiliser le code de la bibliothèque == |
− | 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. | + | 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 paramètres complémentaires. |
| | | |
| Une fois l'instance de la classe '''Adafruit_CharLCDPlate''' créée, il y a quelques fonctions utiles pour interagir avec l'afficheur: | | Une fois l'instance de la classe '''Adafruit_CharLCDPlate''' créée, il y a quelques fonctions utiles pour interagir avec l'afficheur: |
Ligne 84 : |
Ligne 84 : |
| 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). | | 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 />
| + | === En détails === |
− | | + | La première chose à faire est de créer une instance de la classe Adafruit_CharLCDPlate . La classe sait comment dialoguer avec la carte d'extension, le constructeur de la classe est préconfiguré pour la carte LCD. |
− | 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.
| |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
− | # Initialize the LCD using the pins | + | # Initialise le LCD en utilisant le bonne broches |
| lcd = LCD.Adafruit_CharLCDPlate() | | lcd = LCD.Adafruit_CharLCDPlate() |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | 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.
| + | La seconde différence dans '''Adafruit_CharLCDPlate''' est l'ajout d'une fonction qui permet de tester les boutons qui sont pressés. Voyez dans le code d'exemple ci-dessous les différents appels à la fonction {{fname|is_pressed}} pour tester chacun des boutons. La fonction {{fname|is_pressed}} retourne True si le bouton est pressé. |
| | | |
− | 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)}}.
| + | Par exemple, pour tester si le bouton de sélection "select" est pressé, nous utilisation vous pouvez appeler {{fname|is_presssed(LCD.SELECT)}}, pour tester le bouton droit ("right" en anglais) nous utiliserons alors {{fname|is_pressed(LCD.RIGHT)}}. |
| | | |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
− | # Make list of button value, text, and backlight color. | + | # Faire une liste avec valeur_de_bouton + texte + couleur_retro_eclairage. |
| buttons = ( (LCD.SELECT, 'Select', (1,1,1)), | | buttons = ( (LCD.SELECT, 'Select', (1,1,1)), |
| (LCD.LEFT, 'Left' , (1,0,0)), | | (LCD.LEFT, 'Left' , (1,0,0)), |
Ligne 107 : |
Ligne 106 : |
| print 'Press Ctrl-C to quit.' | | print 'Press Ctrl-C to quit.' |
| while True: | | while True: |
− | # Loop through each button and check if it is pressed. | + | # Passer chaque bouton en revue pour |
| + | # voir s'il est pressé |
| for button in buttons: | | for button in buttons: |
| if lcd.is_pressed(button[0]): | | if lcd.is_pressed(button[0]): |
− | # Button is pressed, change the message and backlight. | + | # SI le bouton est presse ALORS chager le message et le retro-eclairage. |
| lcd.clear() | | lcd.clear() |
| lcd.message(button[1]) | | lcd.message(button[1]) |
Ligne 116 : |
Ligne 116 : |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | 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!
| + | Une note finale: comme pour le l'implémentation du LCD avec un MCP230xx [TRADUCTION] IO extender the character LCD plate does not support PWM control of the backlight LEDs! |
| | | |
| That's all there is to using the character LCD plate with the character LCD Python library! | | That's all there is to using the character LCD plate with the character LCD Python library! |