Modifications

Sauter à la navigation Sauter à la recherche
Ligne 71 : Ligne 71 :     
== Surveiller la température ==
 
== Surveiller la température ==
{{traduction}}
+
 
 +
'''1.''' It would be good to monitor the temperature as it changes, so let's put our code into a {{fname|while}} loop and run it again.
 +
 
 +
<nowiki>while True:
 +
  temp = sense.get_temperature()
 +
  temp = round(temp, 1)
 +
  print(temp)</nowiki>
 +
 
 +
When you run the code the temperature values will scroll up the screen with the latest ones at the bottom.
 +
 
 +
'''2.''' Put your thumb over the sensor and hold it there. You should see the measurement start to rise.
 +
 
 +
'''3.''' Blow on it (or give the sensors a short blast from an air duster, if available). The measurement should fall.
 +
 
 +
'''4.''' Pressez {{fname|Ctrl + c}} pour arrêter le programme.
 +
 
 +
== Afficher la température sur la matrice LED ==
 +
 
 +
Think about how you could show the temperature information on the LED matrix in some way (see the LED Matrix guide for more 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:
 +
 
 +
* 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?
 +
* 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.
 +
 
 +
<nowiki>  from sense_hat import SenseHat
 +
 
 +
  sense = SenseHat()
 +
  sense.clear()
 +
 
 +
  tmax = 31
 +
  tmin = tmax - 8
 +
 
 +
  while True:
 +
      temp = sense.get_temperature()
 +
      print(temp)
 +
      temp = int(temp) - tmin
 +
      for x in range(0, 8):
 +
          for y in range(0, temp):
 +
              sense.set_pixel(x, y, 255, 0, 0)
 +
          for y in range(temp, 8):
 +
              sense.set_pixel(x, y, 0, 0, 0)</nowiki>
    
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
29 918

modifications

Menu de navigation