Ligne 1 : |
Ligne 1 : |
| {{RASP-SENSE-HAT-ASTRO-PI-NAV}} | | {{RASP-SENSE-HAT-ASTRO-PI-NAV}} |
− |
| |
− | {{traduction}}
| |
| | | |
| == Senseur de température == | | == Senseur de température == |
| {{bloc-etroit|text=Le Sense HAT met en oeuvre un certain nombre de senseurs... dont un senseur de température. | | {{bloc-etroit|text=Le Sense HAT met en oeuvre un certain nombre de senseurs... dont un senseur de température. |
| | | |
− | Le source anglaise de cette traduction se trouve ici [https://www.raspberrypi.org/learning/astro-pi-guide/sensors/temperature.md www.raspberrypi.org/learning/astro-pi-guide/sensors/temperature.md]
| + | La source anglaise de cette traduction se trouve ici [https://www.raspberrypi.org/learning/astro-pi-guide/sensors/temperature.md www.raspberrypi.org/learning/astro-pi-guide/sensors/temperature.md] |
| }} | | }} |
| | | |
Ligne 88 : |
Ligne 86 : |
| | | |
| == Afficher la température sur la matrice LED == | | == Afficher la température sur la matrice LED == |
| + | Réfléchissez au différentes façons d'afficher l'information de température sur la matrice LED (voyez [[RASP-SENSE-HAT-ASTRO-PI-Matrice|le guide consacré à la Matrice LED pour plus d'information]]). Le choix le plus évident est d'utiliser la fonction {{fname|show_message}}, mais même si cela fonctionnerait, il y a probablement de meilleures façon de le faire. |
| | | |
− | Think about how you could show the temperature information on the LED matrix in some way (voyez [[RASP-SENSE-HAT-ASTRO-PI-Matrice|le guide consacré à la Matrice LED pour plus d'information]]). The obvious choice would be to use the show_message function, but, while this would work, there are probably better ways to do it. For example, you could:
| + | Par exemple, vous pourriez: |
| + | * Utiliser la fonction {{fname|clear}} pour afficher une couleur prédéfinie correspondant à une gamme de température. Par exemple, en bleu pour une température de 0 à 5 degrees. |
| + | * Utiliser la fonction {{fname|clear}} pour afficher une seule couleur mais en modulant la quantité de rouge (0 to 255) en fonction de la mesure de la température? |
| + | * Utiliser la fonction {{fname|set_pixel}} pour afficher une graphique (bar graph) qui monte ou descend comme le ferait un thermomètre. |
| | | |
− | * Use the {{fname|clear}} function to display some predefined colours based on ranges that the temperature falls in. For example 0 to 5 degrees could be blue?
| + | Vous trouverez ci-dessous un embryon de code basé sur la dernière suggestion. Ce code affiche un niveau (une barre) qui couvre 8 degrés Celsius (une ligne horizontal de LEDs pour chaque degré). Le maximum qu'il peut afficher est {{fname|31}} (''hard codé'' dans le programme; n'hésitez pas à modifier cette valeur). Par conséquent, le minimum est {{fname|31 - 8}}, ce qui fait {{fname|23}} degrés celcius. Une erreur survient si la mesure de température se trouve hors de cette gamme de valeur. |
− | * Use the {{fname|clear}} function to display a single colour but change the brightness of red (0 to 255) based on the measured temperature?
| |
− | * Use the {{fname|set_pixel}} function to display a bar that moves up and down similar to a thermometer.
| |
| | | |
− | Below is some starter code for the final suggestion above. This code will display a bar that has a range of 8 degrees Celsius (one degree per horizontal row of LEDs). The maximum it can display is {{fname|31}} (hard coded; feel free to edit this) and so the minimum is {{fname|31 - 8}} which is {{fname|23}}. If the measured temperature goes outside of that range then errors can occur. You can add code to clamp the measured temperature to prevent these errors if you like.
| + | Si vous le voulez, vous pouvez ajouter ajouter du code pour prévenir une telle erreur. |
| | | |
| <nowiki> from sense_hat import SenseHat | | <nowiki> from sense_hat import SenseHat |
Ligne 115 : |
Ligne 115 : |
| sense.set_pixel(x, y, 0, 0, 0)</nowiki> | | sense.set_pixel(x, y, 0, 0, 0)</nowiki> |
| | | |
− | It works by subtracting the minimum value from the measured value which should give a number between 0 and 8. We then use two nested {{fname|for}} loops. The outer loop is for the {{fname|x}} axis and the two inner loops are for the {{fname|y}} axis. We use two loops here because we want to turn all the LEDs below the measurement red with {{fname|set_pixel}} and those above it off. That way the bar will appear to move up and down the y axis following the measured temperature.
| + | Ce programme fonctionne par soustrayant la valeur minimale à la mesure de température. Cela produit un résultat entre 0 et 8. Nous utilisons ensuite deux boucles {{fname|for}} imbriquée pour l'affichage. La boucle externe pour l'axe des {{fname|x}} et deux boucles pour l'axe {{fname|y}} (ces deux boucles se succèdents). Nous utilisons deux boucles pour {{fname|y}} parce que nous voulons activer toutes les LEDs sous la température en rouge avec {{fname|set_pixel}} tandis que la boucle suivante éteint toutes les LEDs au dessus de la température. |
| + | |
| + | De cette façon, la barre donnera l'impression de monter/descendre sur l'axe Y pour suivre la mesure de la température. |
| | | |
− | Remember that you can use {{fname|sense.set_rotation(n)}} (where n is 0, 90, 180 or 270) at the start of the program just after {{fname|sense.clear()}} if you want to change the orientation of the bar.
| + | Si vous voulez modifier l'orientation de votre barre, vous pouvez utiliser {{fname|sense.set_rotation(n)}} au démarrage du programme (où n est 0, 90, 180 ou 270) juste après {{fname|sense.clear()}}. |
| | | |
| {{RASP-SENSE-HAT-ASTRO-PI-TRAILER}} | | {{RASP-SENSE-HAT-ASTRO-PI-TRAILER}} |