Ligne 143 : |
Ligne 143 : |
| | | |
| === Exemple Float === | | === Exemple Float === |
| + | Cet exemple, provenant du fichier {{fname|testflt.py}}, affiche une valeur avec une précision à 3 décimales et l'unité Volts (ex: 12.357 v). |
| + | |
| + | <syntaxhighlight lang="python"># Test the Olimex MOD-LCD1x9 board. |
| + | # |
| + | # Display float value (justified on the right) |
| + | from machine import I2C, Pin |
| + | from time import sleep |
| + | from modlcd19 import MODLCD1x9 |
| + | |
| + | i2c = I2C( sda=Pin(2), scl=Pin(4) ) |
| + | lcd = MODLCD1x9( i2c ) # Active tous les segments |
| + | |
| + | # Afficher une valeur décimale |
| + | volt = 15.125 |
| + | while True: |
| + | # Incrémente la valeur pour démonstration |
| + | volt = volt + 0.033 |
| + | # Afficher un float avec 3 décimales. |
| + | # Affiche également une unité: "v" pour volts |
| + | # voir: https://docs.python.org/3/library/string.html#format-examples |
| + | lcd.write( volt, format='%.3f v' ) |
| + | |
| + | # Donner du temps au LCD pour se rafraîchir |
| + | sleep( 0.100 ) |
| + | |
| + | print( "That's the end folks")</syntaxhighlight> |
| | | |
| == Où acheter == | | == Où acheter == |