diff options
| author | rafael <[email protected]> | 2024-10-20 23:31:53 +0200 |
|---|---|---|
| committer | rafael <[email protected]> | 2024-10-20 23:31:53 +0200 |
| commit | 8baf88f8f4668bdb54c1415bdb8ad62cf2fa5f24 (patch) | |
| tree | f4425105d4ea307ce29d0ad6fea813512e3bfc35 /examples | |
| parent | 7fc09f89e8e4b611a868bc986104762b1c5ba81a (diff) | |
rustfmt
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp23/src/bin/pwm_tb6612fng_motor_driver.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/examples/rp23/src/bin/pwm_tb6612fng_motor_driver.rs b/examples/rp23/src/bin/pwm_tb6612fng_motor_driver.rs index 92c1ff6ba..36b8d9620 100644 --- a/examples/rp23/src/bin/pwm_tb6612fng_motor_driver.rs +++ b/examples/rp23/src/bin/pwm_tb6612fng_motor_driver.rs | |||
| @@ -1,23 +1,23 @@ | |||
| 1 | //! # PWM TB6612FNG motor driver | 1 | //! # PWM TB6612FNG motor driver |
| 2 | //! | 2 | //! |
| 3 | //! This example shows the use of a TB6612FNG motor driver. The driver is built on top of embedded_hal and the example demonstrates how embassy_rp can be used to interact with ist. | 3 | //! This example shows the use of a TB6612FNG motor driver. The driver is built on top of embedded_hal and the example demonstrates how embassy_rp can be used to interact with ist. |
| 4 | 4 | ||
| 5 | #![no_std] | 5 | #![no_std] |
| 6 | #![no_main] | 6 | #![no_main] |
| 7 | 7 | ||
| 8 | use assign_resources::assign_resources; | ||
| 8 | use defmt::*; | 9 | use defmt::*; |
| 9 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 10 | use embassy_rp::block::ImageDef; | 11 | use embassy_rp::block::ImageDef; |
| 11 | use embassy_rp::config::Config; | 12 | use embassy_rp::config::Config; |
| 13 | use embassy_rp::gpio; | ||
| 12 | use embassy_rp::gpio::Output; | 14 | use embassy_rp::gpio::Output; |
| 13 | use embassy_rp::peripherals; | 15 | use embassy_rp::peripherals; |
| 14 | use embassy_rp::gpio; | ||
| 15 | use embassy_rp::pwm; | 16 | use embassy_rp::pwm; |
| 16 | use embassy_time::Duration; | 17 | use embassy_time::Duration; |
| 17 | use embassy_time::Timer; | 18 | use embassy_time::Timer; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | use tb6612fng::{DriveCommand, Motor, Tb6612fng}; | 19 | use tb6612fng::{DriveCommand, Motor, Tb6612fng}; |
| 20 | use assign_resources::assign_resources; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 21 | 21 | ||
| 22 | /// Maximum PWM value (fully on) | 22 | /// Maximum PWM value (fully on) |
| 23 | const PWM_MAX: u16 = 50000; | 23 | const PWM_MAX: u16 = 50000; |
| @@ -94,21 +94,20 @@ async fn main(_spawner: Spawner) { | |||
| 94 | Timer::after(Duration::from_secs(2)).await; | 94 | Timer::after(Duration::from_secs(2)).await; |
| 95 | 95 | ||
| 96 | // actively brake | 96 | // actively brake |
| 97 | info!("brake"); | 97 | info!("brake"); |
| 98 | control.motor_a.drive(DriveCommand::Brake).unwrap(); | 98 | control.motor_a.drive(DriveCommand::Brake).unwrap(); |
| 99 | control.motor_b.drive(DriveCommand::Brake).unwrap(); | 99 | control.motor_b.drive(DriveCommand::Brake).unwrap(); |
| 100 | Timer::after(Duration::from_secs(1)).await; | 100 | Timer::after(Duration::from_secs(1)).await; |
| 101 | 101 | ||
| 102 | // slowly turn for 3s | 102 | // slowly turn for 3s |
| 103 | info!( "turn"); | 103 | info!("turn"); |
| 104 | control.motor_a.drive(DriveCommand::Backward(10)).unwrap(); | 104 | control.motor_a.drive(DriveCommand::Backward(10)).unwrap(); |
| 105 | control.motor_b.drive(DriveCommand::Forward(10)).unwrap(); | 105 | control.motor_b.drive(DriveCommand::Forward(10)).unwrap(); |
| 106 | Timer::after(Duration::from_secs(3)).await; | 106 | Timer::after(Duration::from_secs(3)).await; |
| 107 | 107 | ||
| 108 | // and put the driver in standby mode and wait for 5s | 108 | // and put the driver in standby mode and wait for 5s |
| 109 | info!( "standby"); | 109 | info!("standby"); |
| 110 | control.enable_standby().unwrap(); | 110 | control.enable_standby().unwrap(); |
| 111 | Timer::after(Duration::from_secs(5)).await; | 111 | Timer::after(Duration::from_secs(5)).await; |
| 112 | } | 112 | } |
| 113 | } | 113 | } |
| 114 | |||
