Added more modularity and config.
This commit is contained in:
29
src/motors.rs
Normal file
29
src/motors.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use rppal::gpio::OutputPin;
|
||||
use rppal::pwm::Pwm;
|
||||
|
||||
pub struct Motor {
|
||||
pub in1: OutputPin,
|
||||
pub in2: OutputPin,
|
||||
pub pwm: Pwm,
|
||||
}
|
||||
|
||||
|
||||
impl Motor {
|
||||
pub fn forward(&mut self, speed: f64) {
|
||||
self.in1.set_high();
|
||||
self.in2.set_low();
|
||||
self.pwm.set_duty_cycle(speed).unwrap();
|
||||
}
|
||||
|
||||
pub fn backward(&mut self, speed: f64) {
|
||||
self.in1.set_low();
|
||||
self.in2.set_high();
|
||||
self.pwm.set_duty_cycle(speed).unwrap();
|
||||
}
|
||||
|
||||
pub fn stop(&mut self) {
|
||||
self.in1.set_low();
|
||||
self.in2.set_low();
|
||||
self.pwm.set_duty_cycle(0.0).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user