45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
//! This example shows how to use PWM (Pulse Width Modulation) in the RP2040 chip.
|
|
//!
|
|
//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use defmt::*;
|
|
use embassy_executor::Spawner;
|
|
use embassy_rp::block::ImageDef;
|
|
use embassy_rp::pwm::{Config, Pwm};
|
|
use embassy_time::Timer;
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
#[link_section = ".start_block"]
|
|
#[used]
|
|
pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe();
|
|
|
|
// Program metadata for `picotool info`
|
|
#[link_section = ".bi_entries"]
|
|
#[used]
|
|
pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [
|
|
embassy_rp::binary_info_rp_cargo_bin_name!(),
|
|
embassy_rp::binary_info_rp_cargo_version!(),
|
|
embassy_rp::binary_info_rp_program_description!(c"Blinky"),
|
|
embassy_rp::binary_info_rp_program_build_attribute!(),
|
|
];
|
|
|
|
#[embassy_executor::main]
|
|
async fn main(_spawner: Spawner) {
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
let mut c: Config = Default::default();
|
|
c.top = 0x8000;
|
|
c.compare_b = 8;
|
|
let mut pwm = Pwm::new_output_b(p.PWM_SLICE4, p.PIN_25, c.clone());
|
|
|
|
loop {
|
|
info!("current LED duty cycle: {}/32768", c.compare_b);
|
|
Timer::after_secs(1).await;
|
|
c.compare_b = c.compare_b.rotate_left(4);
|
|
pwm.set_config(&c);
|
|
}
|
|
}
|