unicorn-hat-extras
High-level convenience features for the unicorn-hat library.
This crate provides text rendering, scrolling animations, and frame buffers built on top of the core unicorn-hat crate. Perfect for creating ticker-tape displays, notifications, and smooth animations on your Pimoroni Unicorn HAT.
Features
- 📝 Text Rendering: 5×5 bitmap font optimized for 8×8 displays
- 📜 Scrolling Animations: Smooth text scrolling in all 4 directions
- 🎞️ Frame Buffers: Double-buffering for flicker-free animations
- 🎨 Easy Integration: Works seamlessly with core primitives and drawing functions
Installation
Add both crates to your Cargo.toml:
[]
= "0.1"
= "0.1"
Quick Start
Simple Text Display
use ;
use ;
Scrolling Ticker Tape
use thread;
use Duration;
use ;
use FONT_5X5;
use ;
Double-Buffered Animation
use ;
use Frame;
Examples
Run the included examples to see what's possible:
# Horizontal scrolling ticker tape
# Vertical scrolling demonstrations
# Frame buffer and animation techniques
API Overview
Font Module (font)
FONT_5X5: 5×5 pixel bitmap font (ASCII 32-126)draw_char(buffer, font, x, y, ch, color): Draw a single characterdraw_text(buffer, font, x, y, text, color): Draw a text string
Coordinates can be negative for smooth off-screen rendering and scrolling effects.
Scroller Module (scroller)
Scroller::new(text, font, color, direction): Create a scrolling text animationscroller.step(): Advance the scroll positionscroller.render(buffer): Draw the current framescroller.set_speed(pixels_per_step): Control scroll speedscroller.is_complete(): Check if text has scrolled off-screen
Supports all 4 directions: Left, Right, Up, Down.
Frame Module (frame)
Frame::new(): Create an 8×8 off-screen bufferFrame::with_color(color): Create a frame filled with a colorframe.set_pixel(x, y, color): Modify pixels off-screenframe.get_all(): Get the complete frame bufferUnicornHat::show_frame(frame_data): Display a frame buffer
Use Frame for double-buffering and preparing complex scenes before display.
Font Details
The included FONT_5X5 font covers printable ASCII (characters 32-126) and is optimized for readability on small 8×8 displays. Each character is 5 pixels wide and 5 pixels tall, with automatic 1-pixel spacing between characters.
Performance Tips
- Use
Framefor complex scenes to avoid partial updates being visible - Adjust
Scrollerspeed withset_speed()to match your desired animation framerate - Call
hat.clear()before rendering each frame for smooth scrolling - Negative coordinates are handled efficiently - no need to check bounds manually
Integration with Core Library
All extras functions work with any type implementing the PixelBuffer trait, including:
UnicornHat(direct hardware rendering)Frame(off-screen rendering)TestBuffer(for unit testing)
This means you can mix and match core primitives (lines, rectangles, gradients) with text rendering and scrolling seamlessly.
Requirements
- Requires the
unicorn-hatcore library - Hardware: Pimoroni Unicorn HAT (8×8) on Raspberry Pi
- Must run with
sudo(see mainunicorn-hatcrate docs for details)
License
MIT License - see the workspace root LICENSE file for details.
More Information
For more details about the core library, hardware setup, and permissions, see the main README.