Skip to content

Commit e7c4cef

Browse files
committed
messages from leds prog
1 parent a9566a5 commit e7c4cef

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/bin/bbcTest2.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
#[macro_use(entry, exception)]
5+
extern crate microbit;
6+
extern crate cortex_m;
7+
extern crate panic_abort;
8+
extern crate cortex_m_rt;
9+
10+
use cortex_m_rt::ExceptionFrame;
11+
12+
exception!(*, default_handler);
13+
14+
fn default_handler(_irqn: i16) {}
15+
16+
exception!(HardFault, hard_fault);
17+
18+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
19+
loop {}
20+
}
21+
22+
entry!(main_loop);
23+
24+
fn main_loop() -> ! {
25+
// OK, this is a very very optimistic code here.
26+
let p = microbit::Peripherals::take().take().unwrap();
27+
28+
// configuring GPIO pin P0.4 and P0.13 as output
29+
// to control the matrix LED point (COL1, ROW1)
30+
p.GPIO.pin_cnf[4].write(|w| w.dir().output());
31+
p.GPIO.pin_cnf[13].write(|w| w.dir().output());
32+
p.GPIO.out.write(|w| unsafe { w.bits(1 << 13) });
33+
34+
let mut state: bool = true;
35+
loop {
36+
// some simple delay with busy waiting
37+
for _ in 0..1000 {
38+
cortex_m::asm::nop();
39+
}
40+
41+
// toggling the state variable that represents the blinking
42+
state = !state;
43+
44+
if state {
45+
// turn the LED on, but setting P0.4 to LOW and PO.13 to HIGH
46+
p.GPIO.out.write(|w| unsafe { w.bits(1 << 13) });
47+
} else {
48+
// turn the LED off by setting both GPIO pins to LOW.
49+
p.GPIO.out.write(|w| unsafe { w.bits(0) });
50+
}
51+
}
52+
}

src/bin/leds.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@
33

44
extern crate panic_halt;
55
// github.com therealprof / microbit
6+
use core::fmt::Write;
67
use cortex_m_rt::entry;
78
use microbit::led::Display;
89
//use microbit::hal::i2c;
910
use nrf51::Peripherals;
1011
use nrf51_hal::delay::Delay;
1112
use nrf51_hal::prelude::*;
13+
use nrf51_hal::serial::{Serial, BAUD115200};
1214

1315
#[entry]
1416
fn main() -> ! {
17+
// let vector = vec![1, 3, 4, 5, 3]; // cannot find macro `vec!` in this scope
18+
let _vc = [1,2,3,4,5];
19+
let _mx = _vc.iter().max().unwrap();
20+
21+
1522
if let Some(p) = Peripherals::take() {
23+
let gpio = p.GPIO.split();
24+
let tx_pin = gpio.pin24.into_push_pull_output().downgrade();
25+
let rx_pin = gpio.pin25.into_floating_input().downgrade();
26+
let (mut tx, _) = Serial::uart0(p.UART0, tx_pin, rx_pin, BAUD115200).split();
27+
write!(tx, "test output message\n\r").unwrap();
1628
let mut delay = Delay::new(p.TIMER0);
17-
let gpio = p.GPIO.split();
29+
// let gpio = p.GPIO.split();
1830
let col1 = gpio.pin4.into_push_pull_output();
1931
let col2 = gpio.pin5.into_push_pull_output();
2032
let col3 = gpio.pin6.into_push_pull_output();
@@ -30,7 +42,8 @@ fn main() -> ! {
3042
let mut leds = Display::new(
3143
col1, col2, col3, col4, col5, col6, col7, col8, col9, row1, row2, row3,
3244
);
33-
45+
//https://www.mathworks.com/help/supportpkg/microbit/ref/5x5ledmatrix.html
46+
//https://microbit.org/guide/hardware/leds/
3447
let checker_a = [
3548
[1, 0, 1, 0, 1],
3649
[0, 1, 0, 1, 0],

0 commit comments

Comments
 (0)