GithubHelp home page GithubHelp logo

jp-96 / pxt-mstate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jp-rad/pxt-mstate

0.0 0.0 0.0 1.73 MB

The pxt-mstate extension is a user-defined extension for micro:bit that simplifies state machine coding and visualization using block coding and state diagrams.

Home Page: https://jp-rad.github.io/pxt-mstate/

License: MIT License

Shell 8.70% Ruby 0.13% C++ 1.16% C 0.90% TypeScript 86.70% Makefile 0.13% Dockerfile 2.28%

pxt-mstate's Introduction

Open this page at GitHub Pages: https://jp-rad.github.io/pxt-mstate/

Preface

The pxt-mstate extension is a user-defined extension for micro:bit that enables state machine-based coding.

A state machine is a model that represents transitions from one state to another and can represent complex behavior in a simple way. Usually, state machines are drawn as state diagrams using tools such as UML, from which source code is generated. However, the pxt-mstate extension provides the ability to automatically generate state diagrams from coding.

The pxt-mstate extension allows you to directly define states and transitions using block coding, and to traverse states in response to triggers. You can also visualize them in a state diagram to understand the behavior of your state machine.

Get the pxt-mstate extension into your projects and enjoy programming with state machines! ๐Ÿ˜Š.

Use as Extension

This repository can be added as an extension in MakeCode.

Edit this project Build status badge

To edit this repository in MakeCode.

Blocks preview

A rendered view of the blocks

Example

mstate.defineState(StateMachines.M0, "State1", function () {
    mstate.descriptionUml("Blink Heart Icon")
    mstate.onState(500, function (tickcount) {
        if (0 == tickcount) {
            blinkLED(false)
            basic.showIcon(IconNames.Heart, 20)
        } else {
            blinkLED(true)
        }
    })
    mstate.onExit(function () {
        blinkLED(false)
        basic.showIcon(IconNames.Happy)
    })
    mstate.onTrigger("Trigger1", [""], function () {
        mstate.traverse(StateMachines.M0, 0)
    })
})
function blinkLED(enabled: boolean) {
    if (!(enabled)) {
        blink = 1
    }
    led.setBrightness(blink * 155 + 100)
    blink += 1
    blink = blink % 2
}
input.onButtonPressed(Button.A, function () {
    mstate.start(StateMachines.M0, "State1")
})
input.onButtonPressed(Button.B, function () {
    mstate.send(StateMachines.M0, "Trigger1")
})
let blink = 0
mstate.exportUml(StateMachines.M0, "State1")
basic.showString("M")

UML

A rendered view of UML

Metadata (used for search, rendering)

  • for PXT/microbit
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>

pxt-mstate's People

Contributors

jp-96 avatar jp-rad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.