From 9d54521675d5a56c2b0890e056f01fe611c52a7e Mon Sep 17 00:00:00 2001 From: ImplFerris Date: Tue, 12 Nov 2024 09:15:21 +0530 Subject: [PATCH] active-buzzer --- src/SUMMARY.md | 1 + src/buzzer/active-beep.md | 55 +++++++++++++++++++++++++++++++++++++++ src/index.md | 5 ++++ 3 files changed, 61 insertions(+) create mode 100644 src/buzzer/active-beep.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 0c5b8fe..318dad7 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -33,5 +33,6 @@ - [Music module](./buzzer/music-module.md) - [got module](./buzzer/got-module.md) - [Play](./buzzer/play.md) + - [Active Beep](./buzzer/active-beep.md) - [Resources](./resources.md) diff --git a/src/buzzer/active-beep.md b/src/buzzer/active-beep.md new file mode 100644 index 0000000..c22172e --- /dev/null +++ b/src/buzzer/active-beep.md @@ -0,0 +1,55 @@ +## Beeping with an Active Buzzer + +Since you already know that an active buzzer is simple to use, you can make it beep just by powering it. In this exercise, we'll make it beep with just a little code. + + +### Hardware Requirements +- **Active Buzzer** +- **Female-to-Male** or **Male-to-Male** (depending on your setup) + +We'll use the Embassy HAL for this project. + + +## Project from template + +To set up the project, run: +```sh +cargo generate --git https://github.com/ImplFerris/pico2-template.git +``` +When prompted, give your project a name, like "active-beep," and select `embassy` as the HAL. + +Then, navigate into the project folder: +```sh +cd PROJECT_NAME +# For example, if you named your project "active-beep": +# cd active-beep +``` + +All you need to do is change the output pin from 25 to 15 in the template code. + +```rust +// Active Buzzer +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + let mut led = Output::new(p.PIN_15, Level::Low); // Changed line + + loop { + led.set_high(); + Timer::after_millis(500).await; + + led.set_low(); + Timer::after_millis(500).await; + } +} +``` + + +## Clone the existing project +You can clone (or refer) project I created and navigate to the `active-beep` folder. + +```sh +git clone https://github.com/ImplFerris/pico2-projects +cd pico2-projects/active-beep +``` + diff --git a/src/index.md b/src/index.md index 226972a..638678c 100644 --- a/src/index.md +++ b/src/index.md @@ -12,3 +12,8 @@ We will be using the Raspberry Pi Pico 2 (RP2350 chip). It features the new RP2 For detailed technical information, specifications, and guidelines, refer to the official datasheets: * [Pico 2 Datasheet](https://datasheets.raspberrypi.com/pico/pico-2-datasheet.pdf) * [RP2350 chip Datasheet](https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf) + + +## Support me + +You can support me by starring this project on [GitHub](https://github.com/ImplFerris/pico-pico) or sharing this book with others 😊