1.5 KiB
LED
Let us now turn on an LED! But how?
Well, first we should look at the documentation of our crate, and you should be able to figure out how to get access to the gpio, and set individual pins high and low:
if let Some(p) = microbit::Peripherals::take() {
let mut gpio = p.GPIO.split();
let mut pin1 = gpio.pin1.into_push_pull_output();
pin1.set_high();
}
Next we need to see how these pins are hooked up, for that we need the micro:bit schematics linked to at the bottom of the hardware overview. On the first sheet you should find a diagram with a grid of numbered LEDs.
If you do not know much about electronics: Each row and column (labelled ROW and COL) represent a GPIO output pin. The components labelled LED are light emitting diodes. LEDs only let current flow one way, and only emit light when current is flowing. If a row is set high, high voltage, and a column is set low, low voltage, the LED at the point that they cross will have a potential difference across it; current will flow and it will light up.
The 5x5 array of LEDs are actually wired up as a 3x9 array (3 rows by 9 columns), with 2 missing. This is usually done to make the circuit design easier.
The fifth sheet shows how each row and column correspond to each GPIO pin.
You should now have enough information to try and turn on an LED.