Skip to content

Commit

Permalink
external led
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplFerris committed Oct 21, 2024
1 parent dcad6ca commit 3cedec3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
- [With rp-rs](./blinky/rp-rs.md)
- [PWM](./blinky/pwm.md)
- [With embassy](./blinky/embassy.md)
- [Using External LED](./blinky/external-led.md)
- [Resources](./resources.md)
50 changes: 50 additions & 0 deletions src/blinky/external-led.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Blinking an External LED

In this section, we’ll use an external LED to blink.

You'll need some basic electronic components

**Hardware Requirements**
- LED
- Resistor
- Jumper wires

Refer the [Raspberry pi guide](https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/7) for the hardware setup. I actually used it with breadboard instead.

## Components Overview

1. LED
An LED (Light Emitting Diode) emits light when an electric current flows through it. It only lights up if connected correctly. Anode (long leg) of the LED should be connected to positive; We will connect it to the GP13. This Cathode (short leg) should be connected to to ground(GND).

Note: Always use a resistor with LEDs. Without it, excessive current could damage the LED or even cause it to explode.

2. Resistors
A resistor regulates the flow of current in a circuit. Its value is measured in Ohms (Ω). We use resistors to limit current and protect components, such as LEDs. Resistors are labeled with color bands that represent their resistance value.

<img style="display: block; margin: auto;" alt="pico2" src="../images/pico-external-led.png"/>

## Code
There isn't much change in the code. We showcase how to blink an external LED connected to GPIO 13. The code uses a push-pull output configuration to control the LED state. By setting the pin high, the LED is turned on, and by setting it low, the LED is turned off. This process is repeated in an infinite loop with a delay of 200 milliseconds between each state change, allowing the LED to blink at a consistent rate.

```rust
let mut led_pin = pins.gpio13.into_push_pull_output();

loop {
led_pin.set_high().unwrap();
delay.delay_ms(200);
led_pin.set_low().unwrap();
delay.delay_ms(200);
}
```

## Clone the existing project
You can clone the blinky project I created and navigate to the `external-led` folder to run this version of the blink program:

```sh
git clone https://github.com/ImplFerris/pico2-blinky
cd pico2-blinky/external-led
```

## How to Run?

You refer the ["Running The Program"](../running.md) section
Binary file added src/images/pico-external-led.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/pico-led.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This section will include a list of resources I find helpful along the way.
## Blog Posts
- [RP2350 Launch Blog by theJPster](https://thejpster.org.uk/blog/blog-2024-08-08/)

## Tutorials

- [Official Raspberry Pi Pico guide](https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/0)

## Other resources
- [Curated list of resources for Embedded Rust](https://github.com/rust-embedded/awesome-embedded-rust)
- [Writing an OS in Rust ](https://os.phil-opp.com/): many useful concepts explained here

0 comments on commit 3cedec3

Please sign in to comment.