mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 08:12:30 +00:00
Update examples
This commit is contained in:
parent
cfc76cec71
commit
1a8977db78
@ -15,22 +15,22 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10), Default::default());
|
||||
let max = pwm.get_max_duty();
|
||||
pwm.enable(Channel::Ch1);
|
||||
let ch1_pin = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default());
|
||||
let mut ch1 = pwm.ch1();
|
||||
ch1.enable();
|
||||
|
||||
info!("PWM initialized");
|
||||
info!("PWM max duty {}", max);
|
||||
info!("PWM max duty {}", ch1.max_duty_cycle());
|
||||
|
||||
loop {
|
||||
pwm.set_duty(Channel::Ch1, 0);
|
||||
ch1.set_duty_cycle_fully_off();
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 4);
|
||||
ch1.set_duty_cycle_fraction(1, 4);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 2);
|
||||
ch1.set_dutycycle_fraction(1, 2);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max - 1);
|
||||
ch1.set_duty_cycle(ch1.max_duty_cycle() - 1);
|
||||
Timer::after_millis(300).await;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) {
|
||||
// construct ws2812 non-return-to-zero (NRZ) code bit by bit
|
||||
// ws2812 only need 24 bits for each LED, but we add one bit more to keep PWM output low
|
||||
|
||||
let max_duty = ws2812_pwm.get_max_duty() as u16;
|
||||
let max_duty = ws2812_pwm.max_duty_cycle();
|
||||
let n0 = 8 * max_duty / 25; // ws2812 Bit 0 high level timing
|
||||
let n1 = 2 * n0; // ws2812 Bit 1 high level timing
|
||||
|
||||
@ -84,7 +84,7 @@ async fn main(_spawner: Spawner) {
|
||||
let pwm_channel = Channel::Ch1;
|
||||
|
||||
// make sure PWM output keep low on first start
|
||||
ws2812_pwm.set_duty(pwm_channel, 0);
|
||||
ws2812_pwm.channel(pwm_channel).set_duty(0);
|
||||
|
||||
// flip color at 2 Hz
|
||||
let mut ticker = Ticker::every(Duration::from_millis(500));
|
||||
|
@ -47,10 +47,10 @@ async fn main(spawner: Spawner) {
|
||||
unwrap!(spawner.spawn(blinky(p.PB1)));
|
||||
|
||||
// Connect PB1 and PA8 with a 1k Ohm resistor
|
||||
let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default());
|
||||
pwm.enable(Channel::Ch1);
|
||||
pwm.set_duty(Channel::Ch1, 50);
|
||||
let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default());
|
||||
pwm.ch1().enable();
|
||||
pwm.ch1().set_duty_cycle(50);
|
||||
|
||||
let ch1 = CapturePin::new_ch1(p.PA0, Pull::None);
|
||||
let mut ic = InputCapture::new(p.TIM2, Some(ch1), None, None, None, Irqs, khz(1000), Default::default());
|
||||
|
@ -43,11 +43,10 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
unwrap!(spawner.spawn(blinky(p.PB1)));
|
||||
// Connect PA8 and PA6 with a 1k Ohm resistor
|
||||
let ch1 = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(1), Default::default());
|
||||
let max = pwm.get_max_duty();
|
||||
pwm.set_duty(Channel::Ch1, max / 4);
|
||||
pwm.enable(Channel::Ch1);
|
||||
let ch1_pin = PwmPin::new_ch1(p.PA8, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(1), Default::default());
|
||||
pwm.ch1().set_duty_cycle_fraction(1, 4);
|
||||
pwm.ch1().enable();
|
||||
|
||||
let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000));
|
||||
pwm_input.enable();
|
||||
|
@ -15,22 +15,22 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let ch1 = PwmPin::new_ch1(p.PC0, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10), Default::default());
|
||||
let max = pwm.get_max_duty();
|
||||
pwm.enable(Channel::Ch1);
|
||||
let ch1_pin = PwmPin::new_ch1(p.PC0, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM1, Some(ch1_pin), None, None, None, khz(10), Default::default());
|
||||
let mut ch1 = pwm.ch1();
|
||||
ch1.enable();
|
||||
|
||||
info!("PWM initialized");
|
||||
info!("PWM max duty {}", max);
|
||||
info!("PWM max duty {}", ch1.max_duty_cycle());
|
||||
|
||||
loop {
|
||||
pwm.set_duty(Channel::Ch1, 0);
|
||||
ch1.set_duty_cycle_fully_off();
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 4);
|
||||
ch1.set_duty_cycle_fraction(1, 4);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 2);
|
||||
ch1.set_dutycycle_fraction(1, 2);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max - 1);
|
||||
ch1.set_duty_cycle(ch1.max_duty_cycle() - 1);
|
||||
Timer::after_millis(300).await;
|
||||
}
|
||||
}
|
||||
|
@ -37,22 +37,22 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(config);
|
||||
info!("Hello World!");
|
||||
|
||||
let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10), Default::default());
|
||||
let max = pwm.get_max_duty();
|
||||
pwm.enable(Channel::Ch1);
|
||||
let ch1_pin = PwmPin::new_ch1(p.PA6, OutputType::PushPull);
|
||||
let mut pwm = SimplePwm::new(p.TIM3, Some(ch1_pin), None, None, None, khz(10), Default::default());
|
||||
let mut ch1 = pwm.ch1;
|
||||
ch1.enable();
|
||||
|
||||
info!("PWM initialized");
|
||||
info!("PWM max duty {}", max);
|
||||
info!("PWM max duty {}", ch1.max_duty_cycle());
|
||||
|
||||
loop {
|
||||
pwm.set_duty(Channel::Ch1, 0);
|
||||
ch1.set_duty_cycle_fully_off();
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 4);
|
||||
ch1.set_duty_cycle_fraction(1, 4);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max / 2);
|
||||
ch1.set_dutycycle_fraction(1, 2);
|
||||
Timer::after_millis(300).await;
|
||||
pwm.set_duty(Channel::Ch1, max - 1);
|
||||
ch1.set_duty_cycle(ch1.max_duty_cycle() - 1);
|
||||
Timer::after_millis(300).await;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user