scroll_bottom_top/
scroll-bottom-top.rs

1#[cfg(feature = "default")]
2extern crate sensehat_screen;
3
4#[cfg(feature = "default")]
5use sensehat_screen::{FontCollection, PixelColor, Screen, Scroll};
6
7#[cfg(not(feature = "default"))]
8fn main() {
9    unimplemented!("This examples needs the 'default' features.");
10}
11
12#[cfg(feature = "default")]
13fn main() {
14    // Connect to our LED Matrix screen.
15    let mut screen = Screen::open("/dev/fb1").unwrap();
16
17    // Get the default `FontCollection`.
18    let fonts = FontCollection::new();
19    // Create a sanitized `FontString`.
20    let sanitized = fonts.sanitize_str(" ^^^123^^^ ").unwrap();
21    // Render the `FontString` as a vector of pixel frames, with
22    // a stroke color of CYAN and a BLACK background.
23    let pixel_frames = sanitized.pixel_frames(PixelColor::CYAN, PixelColor::BLACK);
24
25    // Create a `Scroll` from the pixel frame vector.
26    let scroll = Scroll::new(&pixel_frames);
27
28    // Consume the `FrameSequence` returned by the `bottom_to_top` method.
29    scroll.bottom_to_top().for_each(|frame| {
30        println!("Now printing:");
31        println!("{:?}", frame);
32        screen.write_frame(&frame.frame_line());
33        ::std::thread::sleep(::std::time::Duration::from_millis(250));
34    });
35}