| Ligne 82 : |
Ligne 82 : |
| | * '''setup''' : function setting-up the hardware of your DIN project. Called function receives ''din'' object is as parameter. | | * '''setup''' : function setting-up the hardware of your DIN project. Called function receives ''din'' object is as parameter. |
| | * '''loop''' : async function executing the ''userloop'' code. The ''din'' object is received as parameter. Called function receives the ''din'' object as parameter. | | * '''loop''' : async function executing the ''userloop'' code. The ''din'' object is received as parameter. Called function receives the ''din'' object as parameter. |
| − | * '''on_task_create''' : callback event | + | * '''on_task_create''' : callback event allowing the user code to insert its own project tasks. |
| | + | |
| | + | The exemple here below shows how to create the ''userloop'' and the ''setup'' function. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | from mydin import configure |
| | + | from mydin.pico import Pico3Mod |
| | + | from mydin.backplane.relays import TwoRelay3Mod |
| | + | import time, sys |
| | + | |
| | + | from serlcd import SerLCD |
| | + | |
| | + | # Which Controler + Backplane to use |
| | + | din = configure( Pico3Mod, TwoRelay3Mod ) |
| | + | |
| | + | def setup( din ): |
| | + | # Add a new attribute to "din" instance |
| | + | din.lcd = SerLCD( din.i2c, cols=16, rows=4 ) |
| | + | din.lcd.backlight( (0,0,255) ) # Blue |
| | + | din.lcd.set_cursor( (7,1) ) # column,line (0 à N-1) |
| | + | din.lcd.print( "MyDin" ) |
| | + | din.lcd.set_cursor( (3,2) ) # column,line (0 à N-1) |
| | + | din.lcd.print( "by MCHobby.be") |
| | + | din.lcd_last_update = time.ticks_ms() |
| | + | |
| | + | async def loop( din ): |
| | + | """ called again and again (like Arduino) """ |
| | + | |
| | + | # Update LCD once every 5 seconds |
| | + | if time.ticks_diff( time.ticks_ms(), din.lcd_last_update )>5000: |
| | + | din.lcd.clear() |
| | + | din.lcd.print("Internal Temp:" ) |
| | + | din.lcd.set_cursor( (3,1) ) |
| | + | din.lcd.print( "%2.2f C" % din.internal_temperature ) |
| | + | din.lcd_last_update = time.ticks_ms() |
| | + | |
| | + | |
| | + | din.setup( setup=setup, loop=loop ) |
| | + | din.run() |
| | + | </syntaxhighlight> |
| | + | |
| | + | Example with tasks creation is available on the [ micropython-mydin] repository. |