logo elektroda
logo elektroda
X
logo elektroda

Micropython in ESP32 - efficient event waiting in the main program

TvWidget 354 2
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19781165
    TvWidget
    Level 38  
    I want to test Micropython in practice on the ESP32. However, I have not had any contact with this language so far. Let's assume that there is a procedure called when an event occurs, e.g:
    Code: Python
    Log in, to see the code
    .

    How in the main program to effectively wait for an event to occur?
    Is the simplest solution, i.e. a while loop, a good one ?
    Code: Python
    Log in, to see the code
  • ADVERTISEMENT
  • #3 19781558
    TvWidget
    Level 38  
    Sometimes it can be difficult to write a program that only operates on events and the code itself becomes unreadable.
    Let's assume that I need to implement communication via some interface. Establishing a connection, sending and receiving etc. generate the corresponding events.
    So I can handle all the events in this way:
    Code: Python
    Log in, to see the code
    .
    The main program could look like this:
    Code: Python
    Log in, to see the code
    .
    Of course, what I have called the main program can also be placed in an interrupt. The whole thing will work as an automaton. In real
    cases, however, such an automaton can be very complicated. It is much simpler to write a linear program like the one above.
    Is it effective to wait in a while loop for successive events? Perhaps some other special mechanism has been created for this.
ADVERTISEMENT