| Ligne 46 : |
Ligne 46 : |
| | | | |
| | <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
| − | x
| + | from mydin import configure |
| | + | from mydin.pico import Pico3Mod |
| | + | from mydin.backplane.relays import TwoRelay3Mod |
| | + | |
| | + | # Which Controler + Backplane to use |
| | + | din = configure( Pico3Mod, TwoRelay3Mod ) |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | + | |
| | + | Creating the {{fname|din}} object will show initialization information onto the REPL session. |
| | + | |
| | + | In this case, this shows the local time as reloaded from the real time clock. |
| | + | |
| | + | <syntaxhighlight> |
| | + | mcu localtime: 1/1/2000 0:1:44 |
| | + | </syntaxhighlight> |
| | + | |
| | + | from now, the {{fname|din}} instance allows the user script to access all the behavior of controler and the backplane. |
| | + | |
| | + | Up to this point, the code is still running the procedural way. |
| | + | |
| | + | This is where to "procedural" user code could be inserted. |
| | + | |
| | + | === Step 3: going asynchronous === |
| | + | |
| | + | If you want to develop asynchronous code for myDin then following declaration must be added. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | async def loop( din ): |
| | + | """ called again and again (like Arduino) """ |
| | + | # User script here |
| | + | |
| | + | din.setup( setup=None, loop=loop ) |
| | + | din.run() |
| | + | print( "din.run() did exit!!!") |
| | + | </syntaxhighlight> |
| | + | |
| | + | |
| | + | The {{fname|setup()}} call is used to specify a setup method (optional) and a loop method to be called. |
| | + | |
| | + | The '''setup''' parameter can be used to specify some initialization routine. It is quite useful to declare additional sensor, additional components for your project. |
| | + | |
| | + | Once {{fname|din.run()}} is called, the loop is continuously executed! That execution can even be monitored with a watchdog. |
| | + | |
| | + | The {{fname|din.run()}} exits on: |
| | + | * loop() exception |
| | + | * RUN_APP switch placed on STOP position |
| | + | |
| | + | |
| | | | |
| | | | |
| | {{MyDin-TRAILER}} | | {{MyDin-TRAILER}} |