#![no_main]
#![no_std]

extern crate panic_halt;

use cortex_m_rt::entry;
use microbit::led::Display;
use nrf51::Peripherals;
use nrf51_hal::delay::Delay;
use nrf51_hal::prelude::*;

#[entry]
fn main() -> ! {
    if let Some(p) = Peripherals::take() {
        let mut delay = Delay::new(p.TIMER0);
        let gpio = p.GPIO.split();
        let col1 = gpio.pin4.into_push_pull_output();
        let col2 = gpio.pin5.into_push_pull_output();
        let col3 = gpio.pin6.into_push_pull_output();
        let col4 = gpio.pin7.into_push_pull_output();
        let col5 = gpio.pin8.into_push_pull_output();
        let col6 = gpio.pin9.into_push_pull_output();
        let col7 = gpio.pin10.into_push_pull_output();
        let col8 = gpio.pin11.into_push_pull_output();
        let col9 = gpio.pin12.into_push_pull_output();
        let row1 = gpio.pin13.into_push_pull_output();
        let row2 = gpio.pin14.into_push_pull_output();
        let row3 = gpio.pin15.into_push_pull_output();
        let mut leds = Display::new(
            col1, col2, col3, col4, col5, col6, col7, col8, col9, row1, row2, row3,
        );

        let checker_a = [
            [1, 0, 1, 0, 1],
            [0, 1, 0, 1, 0],
            [1, 0, 1, 0, 1],
            [0, 1, 0, 1, 0],
            [1, 0, 1, 0, 1],
        ];
        let checker_b = [
            [0, 1, 0, 1, 0],
            [1, 0, 1, 0, 1],
            [0, 1, 0, 1, 0],
            [1, 0, 1, 0, 1],
            [0, 1, 0, 1, 0],
        ];

        loop {
            leds.display(&mut delay, checker_a, 1000);
            leds.display(&mut delay, checker_b, 1000);
        }
    }
    panic!();
}
