GPIO and LEDs
GPIO
GPIO: General purpose input-output
The GPIO is a block of pins found on nearly all microcontrollers. As the name implies, they are general-purpose, configureable, analog or digital, input or output, electrical pins. Exactly what features each pin has on a given microcontroller will require looking at a datasheet.
Analog vs Digital: Analog signals carry data in their amplitude as they continuously vary over time, whereas digital signals have a fixed rate and fixed amplitudes. Digital signals are usually just 0 or 1, i.e. 0V or 3.3V
LED
LED: Light emitting diode
Let us now turn on an LED! But how?
Many integrated periperals like LEDs and buttons are already connected to certain GPIO pins, so lighting up an LED can be as simple as configuring a GPIO pin to be a digital output.
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:
# #![allow(unused_variables)] #fn main() { // This takes singleton ownership of the micro:bit's peripherals if let Some(p) = microbit::Peripherals::take() { // Take the micro:bit's GPIO let mut gpio = p.GPIO.split(); // Take pin 1 of the GPIO, and configure it as a digital output let mut pin1 = gpio.pin1.into_push_pull_output(); // Set pin 1 high 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 are LEDs. 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.
As you can see, the micro:bit's display LEDs are a bit more complicated than being connected to a single pin. Each LED is connected to 2 pins, where one needs to be high, and the other low for the LED to 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.