Added more modularity and config.

This commit is contained in:
Fast-Blast
2026-03-26 18:09:12 +01:00
parent 6aa848fe3d
commit 59e405cb88
3 changed files with 65 additions and 25 deletions

29
src/motors.rs Normal file
View 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();
}
}