Skip to content

Commit

Permalink
Merge pull request #11 from mr-threepwood/main
Browse files Browse the repository at this point in the history
minor fixes: moving a formula and updating outdated references
  • Loading branch information
BartMassey authored Oct 23, 2024
2 parents fa8fd1c + 6b38a4f commit 43b9f45
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
13 changes: 5 additions & 8 deletions mdbook/src/12-led-compass/magnitude.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@ only thing we have to compute in order to get the magnitude of the magnetic fiel
the magnitude of the 3D vector that our `x` `y` `z` values describe. As you might remember from
school this is simply:

[`magnetic_field()`]: https://docs.rs/lsm303agr/1.1.0/lsm303agr/struct.Lsm303agr.html#method.magnetic_field

Rust does not have floating-point math functions such as `sqrtf()` in `core`, so our `no_std`
program has to get an implementation from somewhere. We use the [libm] crate for this.

[libm]: https://crates.io/crates/libm

``` rust
use libm::sqrtf;
let magnitude = sqrtf(x * x + y * y + z * z);
```

[`magnetic_field()`]: https://docs.rs/lsm303agr/1.1.0/lsm303agr/struct.Lsm303agr.html#method.magnetic_field

Rust does not have floating-point math functions such as `sqrtf()` in `core`, so our `no_std`
program has to get an implementation from somewhere. We use the [libm] crate for this.

[libm]: https://crates.io/crates/libm

Putting all this together in a program (`examples/magnitude.rs`):

``` rust
{{#include examples/magnitude.rs}}
```

Run this with `cargo run --bin magnitude`.
Run this with `cargo run --example magnitude`.

This program will report the magnitude (strength) of the magnetic field in nanotesla (`nT`) and
milligauss (`mG`, where 1 `mG` = 100 `nT`). The magnitude of the Earth's magnetic field is in the
Expand Down
4 changes: 2 additions & 2 deletions mdbook/src/appendix/3-mag-calibration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You have to tilt the micro:bit until all the LEDs on the LED matrix light up. Th
shows the current target LED.

Note that the calibration matrix is printed by the demo program. This matrix can be hard-coded into
a program such as the [chapter 9] compass program (or stored in flash somewhere somehow) to avoid
a program such as the [chapter 12] compass program (or stored in flash somewhere somehow) to avoid
the need to recalibrate every time the user runs the program.

[chapter 9]: ../../12-led-compass/index.html
[chapter 12]: ../../12-led-compass/index.html
7 changes: 2 additions & 5 deletions mdbook/src/explore.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In preemptive multitasking a task that's currently being executed can, at any po
*preempted* (interrupted) by another task. On preemption, the first task will be suspended and the
processor will instead execute the second task. At some point the first task will be resumed.
Microcontrollers provide hardware support for preemption in the form of *interrupts*. We were
introduced to interrupts when we built our snake game in chapter 11.
introduced to interrupts when we built our snake game in [chapter 14](14-snake-game/index.md).

In cooperative multitasking a task that's being executed will run until it reaches a *suspension
point*. When the processor reaches that suspension point it will stop executing the current task and
Expand Down Expand Up @@ -76,10 +76,7 @@ the near future.

### Interrupts

We saw button interrupts briefly in [chapter 11].

[chapter 11](14-snake-game/controls.html)

We saw button interrupts briefly in [chapter 14](14-snake-game/controls.html).
This introduced the key idea: in order to interact with the real world, it is often necessary for
the microcontroller to respond *immediately* when some kind of event occurs.

Expand Down

0 comments on commit 43b9f45

Please sign in to comment.