Modifications

Sauter à la navigation Sauter à la recherche
Ligne 355 : Ligne 355 :  
* Variables
 
* Variables
    +
== Ressentir l'environnement ==
    +
[[Fichier:hat-sense-banner-04.jpg]]
 +
 +
The Sense HAT has a set of environmental sensors for detecting the conditions around it. It can detect:
 +
* Pressure
 +
* Temperature
 +
* Humidity
 +
 +
We can collect these readings using three simple methods:
 +
 +
* {{fname|sense.get_temperature()}} - This will return the temperature in Celsius.
 +
* {{fname|sense.get_pressure()}} - This will return the pressure in millibars.
 +
* {{fname|sense.get_humidity()}} - This will return the humidity as a percentage.
 +
 +
'''1.''' Using these, we could create a simple scrolling text display which could keep people informed about current conditions.
 +
 +
<nowiki>from sense_hat import SenseHat
 +
sense = SenseHat()
 +
 +
while True:
 +
    t = sense.get_temperature()
 +
    p = sense.get_pressure()
 +
    h = sense.get_humidity()
 +
 +
    t = round(t, 1)
 +
    p = round(p, 1)
 +
    h = round(h, 1)
 +
 +
    msg = "Temperature = %s, Pressure=%s, Humidity=%s" % (t,p,h)
 +
 +
    sense.show_message(msg, scroll_speed=0.05)</nowiki>
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
 
{{RASP-SENSE-HAT-ASTRO-PI-TRAILER}}
29 917

modifications

Menu de navigation