Adam Fraser-Kruck
Visualize Your State Machines
Status: Coming up in April 2025!Let's dive into state machines by building an embedded security system!
State machines are an incredibly helpful pattern for embedded systems, but hand-coded state machines can be difficult to understand and maintain, especially as designs become more complex with additional states and transitions.
To make our lives easier, we are going to use StateSmith to visually model our state machines in draw.io and PlantUML.
StateSmith is a cross-platform, free/open source tool for generating state machines in multiple programming languages (C, C++, C#, Java, Python, JavaScript, TypeScript). The generated code is human-readable, has zero dependencies, and is suitable for use with tiny bare-metal microcontrollers, video games, apps, web, computers, and more. It avoids dynamic memory allocations for those focused on safety or performance. Each state machine instance only requires a single byte of RAM.
We'll start by creating a simple button state machine that performs debouncing and long press detection. Then we will connect those button state machines to our Control and Display state machines.
Every step of the way, we will simulate our design using Wokwi (an online electronics simulator) so that you can easily follow along without any physical hardware.