Modifications

Sauter à la navigation Sauter à la recherche
1 173 octets ajoutés ,  22 avril 2025 à 00:19
Ligne 99 : Ligne 99 :  
* RUN_APP switch placed on STOP position
 
* RUN_APP switch placed on STOP position
    +
=== Step 4: setup parameter ===
    +
The ''setup'' parameter when calling the {{fname|setup()}} method can be used to configure additional hardware (or sensors).
 +
 +
The example here below use a setup() routine that creates a [https://shop.mchobby.be/fr/cartes-breakout/1118-bmp280-senseur-de-pression-barometrique-temperature-altitude-33-et-5v-3232100011182-adafruit.html BMP280 athmospheric pressure sensor] then attach it to the {{fname|din}} instance as {{fname|sensor}} attribute.
 +
 +
Then, the {{fname|loop()}} routine can access the {{fname|sensor}} attribute to query the data.
 +
 +
<syntaxhighlight lang="python">
 +
from mydin import configure
 +
from mydin.pico import Pico3Mod
 +
from mydin.backplane.relays import TwoRelay3Mod
 +
 +
from bme280 import *
 +
 +
din = configure( Pico3Mod, TwoRelay3Mod )
 +
 +
def setup( din ):
 +
    # Add a new attribute to "din" instance
 +
    din.sensor = BME280( i2c=din.i2c, address=BMP280_I2CADDR )
 +
 +
async def loop( din ):
 +
    # accessing sensor
 +
    temp, hpa, rh = din.sensor.raw_values
 +
    # ... user code here ...
 +
 +
din.setup( setup=setup, loop=loop )
 +
din.run()
 +
</syntaxhighlight>
 +
 +
{{tmbox | text = The experienced user would notice the {{fname|din.i2c}} as  }}
       
{{MyDin-TRAILER}}
 
{{MyDin-TRAILER}}
32 908

modifications

Menu de navigation