Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Questions about embassy
Hey,
I am playing around with embassy and a microbit v2 (nrf52833 controller), trying to build some kind of robot around the board. Handling IO Pins and driving motors with PWMs already works. But now i stumbled over some problems. Probably because of the type and trait system.
First question is about updating from the crate embassy-nrf (version = "0.3.1") to embassy-nrf (version = "0.7.0"). In the old version something like this worked:
pub async fn ultrasonic_task(trigger_pin: AnyPin, echo_pin: AnyPin) {
// Initialize GPIO pins for the HCSR04 sensor let
let trigger = Output::new(trigger_pin, Level::Low, OutputDrive::Standard);
let echo = Input::new(echo_pin, Pull::None);
}
Use the defined task for example in main.
spawner
.spawn(ultrasonic_task(
peripherals.P0_12.degrade(),
peripherals.P0_17.degrade(),
))
.unwrap();
In 0.7.0 this code doesent work anymore. The degrade function seems to not exist anmymore.I dont find any examples how to pass a pin into a function?
The second problem appears when i try to move my pwm code into a seperate function/task. I have something like this in main:
let peripherals = embassy_nrf::init(Default::default());
let mut pwm = SimplePwm::new_1ch(peripherals.PWM0, peripherals.P0_04);
Would i pass a reference to peripherals into the function or would i move peripherals.PWM0 into the function? If so, how?
Many thanks in advance .
2 posts - 2 participants
🏷️ Rust_feed