Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

文字を表示する

LEDマトリクスにハートの形を表示できました。次はもう一歩進んで、そこにいくつかの文字を表示してみましょう。

まずは文字 'R' を表示してみましょう。

#![allow(unused)]
fn main() {
// 'R' のマトリクス
[
    [1, 1, 1, 0, 0],
    [1, 0, 0, 1, 0],
    [1, 1, 1, 0, 0],
    [1, 0, 1, 0, 0],
    [1, 0, 0, 1, 0],
],
}

テンプレートからプロジェクトを作成する

テンプレートを使って新しいプロジェクトを生成するには、次のコマンドを実行します。

cargo generate --git https://github.com/ImplFerris/mb2-template.git --rev 88d339b

プロジェクト名の入力を求められたら、led-char のような名前を入力します。

プロジェクトが作成されたら、src/main.rs を次のコードで更新します。

完全なコード

#![no_std]
#![no_main]

use embedded_hal::delay::DelayNs;
use microbit::{board::Board, display::blocking::Display, hal::timer::Timer};

use cortex_m_rt::entry;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

#[entry]
fn main() -> ! {
    let board = Board::take().unwrap();

    let mut timer = Timer::new(board.TIMER0);

    let mut display = Display::new(board.display_pins);
    let led_matrix = [
        [1, 1, 1, 0, 0],
        [1, 0, 0, 1, 0],
        [1, 1, 1, 0, 0],
        [1, 0, 1, 0, 0],
        [1, 0, 0, 1, 0],
    ];
    loop {
        display.show(&mut timer, led_matrix, 1000);
        display.clear();
        timer.delay_ms(1000);
    }
}

既存のプロジェクトをクローンする

作成済みのプロジェクトをクローン(または参照)して、led-char フォルダに移動することもできます。

git clone https://github.com/ImplFerris/microbit-projects
cd microbit-projects/bsp/led-char

書き込み

このプログラムを micro:bit に書き込むと、文字が表示されるはずです。

cargo flash