|
SBK_BarDrive Library 2.1.0
LED bar meter control and queued animations for Arduino
|
High-level Arduino library for controlling animated LED bar meters using MAX7219/MAX7221 or HT16K33 drivers. Ideal for prop-making, visual meters, and signal-driven lighting effects.
Version 2.1.0 adds configurable, fixed-storage animation queues, queue index inspection and skipping, non-blocking wait(), single-pixel blinking, safer animation workspace allocation, and AVR-focused RAM and flash optimizations. See CHANGELOG.md for the complete development history. Potential future architecture work is recorded in ROADMAP.md.
Versions prior to 2.0.0 remain deprecated because of internal changes to offset handling and multi-device support.
This library is compatible with any LED matrix or bar display using MAX7219, MAX7221, or HT16K33 drivers — as long as a valid [dev, row, col], aka [device index, anode,cathode], segment mapping is provided or configured using a built-in preset.
When using custom segment mappings with SBK_BarDrive, each segment is defined as a {dev, row, col} — representing the physical LED connection:
{dev, row, col} = {device index, anode, cathode}
This matches the wiring convention of common LED driver ICs:
| Driver | Row (Anode / V+) | Column (Cathode / GND) |
|---|---|---|
| MAX72xx | SEGx (source, V+) | DIGx (sink, GND) |
| HT16K33 | Rx (source, V+) | Cx (sink, GND) |
SBK offers purpose-built PCBs to simplify bar meter wiring, driver integration, and display control. These include:
Some models are available via the SBK Tindie Store or upon request by emailing SmartBuildsKits@gmail.com.
📁 For schematics, 3D models, and PCB source files, visit:
🔗 https://github.com/sbarabe/SBK_PCBs
The SBK_BarDrive library depends on one of the following display driver libraries to function:
| Dependency | Description | Required For |
|---|---|---|
| SBK_MAX72xx | Software SPI driver for MAX7219/MAX7221 LED drivers | MAX72xx-based displays |
| SBK_HT16K33 | I²C driver for HT16K33 LED driver (8x16 matrices or bar displays) | HT16K33-based displays |
You must install at least one of these drivers depending on your hardware.
If using PlatformIO or Arduino Library Manager, these will be installed automatically as dependencies.
To manually install:
Then place them in your Arduino libraries folder.
Download or clone the library into your Arduino libraries folder:
In your Arduino sketch, enable features as needed:
Each SBK_BarDrive animation controller sizes its working buffers from the actual number of segments and allocates them once during construction. The same buffers are reused by every animation, so changing animations does not allocate or free heap memory. Block storage scales with the bar size and keeps the existing maximum of 64 simultaneous blocks.
See animationQueueDemo for a four-entry queue, live logic inversion without restarting the active animation, graceful block-emission shutdown, and a non-blocking wait() entry.
If you want full control over how segments map to physical LED positions, you can supply a custom [device, row, col] mapping array. This is ideal for irregular layouts or displays spanning multiple devices.
These functions start animations and can be chained with modifiers like .loop() or .pause().
These methods allow you to control, manipulate, or conditionally alter animations at runtime. Most are event-driven triggers—ideal for reacting to user input, state transitions, or timed events.
You can chain these calls because they return a reference to the active animation controller:
pause() freezes the current animation and preserves both its state and the visible pixels so that resume() can continue it. stop() fully terminates the current animation, disables looping, clears the pending queue, and clears the mapped pixels in the driver's buffer. Call bar.show() afterward when the cleared buffer must be sent to the display immediately.
All helper functions return a reference to the SBK_BarMeterAnimations object, allowing chainable expressions like:
Up to SBK_BARDRIVE_QUEUE_CAPACITY configured animations can be queued without dynamic allocation. The default capacity is four. Configure an animation, apply any modifiers, and capture it with enqueue():
Calling update() automatically starts the next entry when the current one finishes. queuedAnimations() reports the number still waiting, isQueueRunning() reports whether a queue is active, and queueOverflowed() reports an attempt to exceed the configured capacity. currentQueueIndex() returns the physical queue slot currently playing, or NO_QUEUE_INDEX when none is active. isQueueIndexPlaying(index) provides a direct test, for example:
Use wait(duration) to add a non-blocking delay that preserves the current pixel states:
An individually looped or continuous animation intentionally prevents later entries from starting automatically. Call skipCurrent() to abandon it and immediately continue with the next queued animation. Unlike stop(), skipping does not clear pending entries.
| Class | Purpose |
|---|---|
| SBK_BarMeter | Handles segment mapping and direction logic |
| SBK_BarDrive | Wrapper that adds animation support |
| SBK_BarMeterAnimations | Provides animation control interface |
| SBK_MAX72xx | Software SPI driver for MAX7219/MAX7221 |
| SBK_HT16K33 | I2C driver for HT16K33 8x16 LED matrices |
Licensed under the MIT License.
Licensed under Creative Commons Attribution 4.0 (CC BY 4.0).
You are free to share and adapt the material, provided you give appropriate credit.
Library by Samuel Barabé (Smart Builds & Kits).
✏️ Feel free to customize any URLs or email addresses before publishing!