Double Sided
This commit is contained in:
39
src/main.rs
39
src/main.rs
@@ -1,6 +1,6 @@
|
||||
use rppal::gpio::{Gpio, OutputPin};
|
||||
use rppal::pwm::{Pwm, Channel, Polarity};
|
||||
use std::error::Error;
|
||||
use std::{error::Error, thread, time::Duration};
|
||||
|
||||
struct Motor {
|
||||
in1: OutputPin,
|
||||
@@ -31,20 +31,35 @@ impl Motor {
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let gpio = Gpio::new()?;
|
||||
|
||||
let in1 = gpio.get(27)?.into_output();
|
||||
let in2 = gpio.get(22)?.into_output();
|
||||
// LEFT
|
||||
let left = Motor {
|
||||
in1: gpio.get(27)?.into_output(),
|
||||
in2: gpio.get(22)?.into_output(),
|
||||
pwm: Pwm::with_frequency(Channel::Pwm0, 1000.0, 0.0, Polarity::Normal, true)?,
|
||||
};
|
||||
|
||||
let pwm = Pwm::with_frequency(
|
||||
Channel::Pwm0,
|
||||
1000.0,
|
||||
0.0,
|
||||
Polarity::Normal,
|
||||
true,
|
||||
)?;
|
||||
// RIGHT
|
||||
let right = Motor {
|
||||
in1: gpio.get(23)?.into_output(),
|
||||
in2: gpio.get(24)?.into_output(),
|
||||
pwm: Pwm::with_frequency(Channel::Pwm1, 1000.0, 0.0, Polarity::Normal, true)?,
|
||||
};
|
||||
|
||||
let mut left_motor = Motor { in1, in2, pwm };
|
||||
let mut left = left;
|
||||
let mut right = right;
|
||||
|
||||
left_motor.forward(0.7);
|
||||
// Test: Forward 3 seconds
|
||||
left.forward(1.0);
|
||||
right.forward(1.0);
|
||||
thread::sleep(Duration::from_secs(3));
|
||||
|
||||
left.backward(0.6);
|
||||
right.backward(0.6);
|
||||
thread::sleep(Duration::from_secs(2));
|
||||
|
||||
// Stop
|
||||
left.stop();
|
||||
right.stop();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user