From 6003517941c063b0f4be41595ccf5cf04887a09b Mon Sep 17 00:00:00 2001 From: "lymeng.ly" Date: Mon, 17 Mar 2025 14:02:43 +0100 Subject: [PATCH 1/2] change readme.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a1fd86..df33d19 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# IntroRoboticsLab2 +# First Robotics Lab + + + From 9c0c9ce8af48b5c8bb0af257ae59c0933262f1c2 Mon Sep 17 00:00:00 2001 From: "lymeng.ly" Date: Mon, 17 Mar 2025 14:08:59 +0100 Subject: [PATCH 2/2] Add new motion code --- motion.ino | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 motion.ino diff --git a/motion.ino b/motion.ino new file mode 100644 index 0000000..a77cf67 --- /dev/null +++ b/motion.ino @@ -0,0 +1,54 @@ +#include +#include +#include +#include + + +// declare motors +MeDCMotor _leftMotor(9); +MeDCMotor _rightMotor(10); + +// declare motor speeds +int _leftMotorSpeed = 0; +int _rightMotorSpeed = 0; + +void setup() +{ + Serial.begin(9600); + // set no speed for left and right motors + _leftMotor.run((9)==M1?-(0):(0)); + _rightMotor.run((10)==M1?-(0):(0)); +} + +void loop() +{ + // Move forward + Serial.println("Move forward"); + move(100, 100, 2000); + + // Move backwards + Serial.println("Move backward"); + move(-100, -100, 2000); + + // Turn right + Serial.println("Turn right"); + move(100, -100, 2000); + + // Turn left + Serial.println("Turn left"); + move(-100, 100, 2000); + +} + +void move(int leftMotorSpeed, int rightMotorSpeed, int duration) +{ + _leftMotorSpeed = leftMotorSpeed; + _rightMotorSpeed = rightMotorSpeed; + + _leftMotor.run((9)==M1?-(_leftMotorSpeed):(_leftMotorSpeed)); + _rightMotor.run((10)==M1?-(_rightMotorSpeed):(_rightMotorSpeed)); + delay(duration); + _leftMotor.stop(); + _rightMotor.stop(); + +}