https://github.com/pgularski/upysm
Versatile and flexible Python State Machine library - Micropython Port
https://github.com/pgularski/upysm
finite-state-machine fsm fsm-library micropython micropython-esp32 mit-license python
Last synced: about 2 months ago
JSON representation
Versatile and flexible Python State Machine library - Micropython Port
- Host: GitHub
- URL: https://github.com/pgularski/upysm
- Owner: pgularski
- License: mit
- Created: 2019-01-02T11:28:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-02T17:18:09.000Z (over 6 years ago)
- Last Synced: 2025-02-25T01:38:53.269Z (about 2 months ago)
- Topics: finite-state-machine, fsm, fsm-library, micropython, micropython-esp32, mit-license, python
- Language: Python
- Size: 5.86 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# upysm
Versatile and flexible Python State Machine library - Micropython PortThis repository is basically a set of tools to build and deploy (to pypi) the
Micropython Port of the [pysm](https://github.com/pgularski/pysm) library.It's successfully tested against the ESP-32S ESP-WROOM-32 NodeMCU board.
# Installation
```python
import upip
upip.install('upysm')
```# Usage
Basic usage:```python
import machine
import time
from pysm import State, StateMachine, Eventled = machine.Pin(2, machine.Pin.OUT)
def on_enter(state, event):
led.value(1)
time.sleep(0.1)def on_exit(state, event):
led.value(0)
time.sleep(0.1)on = State('on')
off = State('off')sm = StateMachine('sm')
sm.add_state(on, initial=True)
sm.add_state(off)sm.add_transition(on, off, events=['off'])
sm.add_transition(off, on, events=['on'])on.handlers = {'enter': on_enter, 'exit': on_exit}
off.handlers = {'enter': on_enter, 'exit': on_exit}sm.initialize()
assert sm.state == on
sm.dispatch(Event('off'))
assert sm.state == off
sm.dispatch(Event('on'))
assert sm.state == on```
For more examples and API description refer to the [pysm documentation](http://pysm.readthedocs.io/).