Skip to main content

Versatile and flexible Python State Machine library - Micropython Port

Project description


Versatile and flexible Python State Machine library - Micropython Port

This repository is basically a set of tools to build and deploy (to pypi) the Micropython Port of the pysm library.

It's successfully tested against the ESP-32S ESP-WROOM-32 NodeMCU board.


import upip


Basic usage:

import machine
from pysm import State, StateMachine, Event
import time

led = machine.Pin(2, machine.Pin.OUT)

test_list = []

def on_enter(state, event):
    test_list.append(('enter', state))

def on_exit(state, event):
    test_list.append(('exit', state))

on = State('on')
off = State('off')

sm = StateMachine('sm')
sm.add_state(on, initial=True)

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}


assert sm.state == on
assert sm.state == off
assert sm.state == on

For more examples and API description refer to the pysm documentation.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for upysm, version 0.3.4
Filename, size File type Python version Upload date Hashes
Filename, size upysm-0.3.4-py3-none-any.whl (10.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size upysm-0.3.4.tar.gz (9.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page