From 884fcdae594347cf606213e7fc1da74c3a458701 Mon Sep 17 00:00:00 2001 From: Fast-Blast Date: Wed, 4 Mar 2026 17:36:21 +0100 Subject: [PATCH] Test 1 (ChatGPT Code) --- Cargo.lock | 25 +++++++++++++++++++++++++ src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3a9a66c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "atov-software" +version = "0.1.0" +dependencies = [ + "rppal", +] + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "rppal" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dc171bbe325b04172e18d917c58c2cf1fb5adfd9ffabb1d6b3d62ba4c1c1331" +dependencies = [ + "libc", +] diff --git a/src/main.rs b/src/main.rs index e7a11a9..b152dea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,50 @@ -fn main() { - println!("Hello, world!"); +use rppal::gpio::{Gpio, OutputPin}; +use rppal::pwm::{Pwm, Channel, Polarity}; +use std::error::Error; + +struct Motor { + in1: OutputPin, + in2: OutputPin, + pwm: Pwm, +} + +impl Motor { + fn forward(&mut self, speed: f64) { + self.in1.set_high(); + self.in2.set_low(); + self.pwm.set_duty_cycle(speed).unwrap(); + } + + fn backward(&mut self, speed: f64) { + self.in1.set_low(); + self.in2.set_high(); + self.pwm.set_duty_cycle(speed).unwrap(); + } + + fn stop(&mut self) { + self.in1.set_low(); + self.in2.set_low(); + self.pwm.set_duty_cycle(0.0).unwrap(); + } +} + +fn main() -> Result<(), Box> { + let gpio = Gpio::new()?; + + let in1 = gpio.get(27)?.into_output(); + let in2 = gpio.get(22)?.into_output(); + + let pwm = Pwm::with_frequency( + Channel::Pwm0, + 1000.0, + 0.0, + Polarity::Normal, + true, + )?; + + let mut left_motor = Motor { in1, in2, pwm }; + + left_motor.forward(0.7); + + Ok(()) }