Skip to content
This repository was archived by the owner on Oct 15, 2023. It is now read-only.

Commit 8c99387

Browse files
committed
Format and Rewrite the code more efficiently
We've also fixed #1 by tweaking the physical bot design and using this rewrite for slowing down the motors
1 parent eb4f890 commit 8c99387

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

sumo_bot.ino

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
// Motor RIGHT (Needs to reworked)
2-
int ena = 6;
3-
int in4 = 2;
4-
int in3 = 4;
1+
// Motor Pins - RIGHT
2+
const int enaPin = 6;
3+
const int in4Pin = 2;
4+
const int in3Pin = 4;
55

6-
// Motor LEFT (Needs to reworked)
7-
int enb = 3;
8-
int in2 = 5;
9-
int in1 = 7;
6+
// Motor Pins - LEFT
7+
const int enbPin = 3;
8+
const int in2Pin = 5;
9+
const int in1Pin = 7;
10+
11+
// Speed Values
12+
const int leftSpeed = 255; // Max speed for the left motor
13+
const int rightSpeed = 180; // Reduced speed for the right motor
1014

1115
void setup() {
1216
// Set the motor control pins as output
13-
pinMode(in1, OUTPUT);
14-
pinMode(in2, OUTPUT);
15-
pinMode(in3, OUTPUT);
16-
pinMode(in4, OUTPUT);
17-
pinMode(ena, OUTPUT);
18-
pinMode(enb, OUTPUT);
17+
pinMode(in1Pin, OUTPUT);
18+
pinMode(in2Pin, OUTPUT);
19+
pinMode(in3Pin, OUTPUT);
20+
pinMode(in4Pin, OUTPUT);
21+
pinMode(enaPin, OUTPUT);
22+
pinMode(enbPin, OUTPUT);
1923

2024
// Start the serial connection at 9600 Bauds
2125
Serial.begin(9600);
2226

23-
// set the speed control (255 Max) for the motors
24-
analogWrite(ena, 255); // LEFT
25-
analogWrite(enb, 180); // RIGHT (-75 power)
27+
// Set the speed control (0-255) for the motors
28+
analogWrite(enaPin, leftSpeed);
29+
analogWrite(enbPin, rightSpeed);
2630
}
2731

2832
void loop() {
29-
// Our debug code to prove that the bot is running
33+
// Debug code to demonstrate the movement of the bot
3034
moveForward();
3135
delay(6000);
3236
moveBackward();
@@ -38,42 +42,42 @@ void loop() {
3842
stopMoving();
3943
}
4044

41-
// Bot moves forward
45+
// Function to move the bot forward
4246
void moveForward() {
43-
digitalWrite(in1, HIGH);
44-
digitalWrite(in2, LOW);
45-
digitalWrite(in3, HIGH);
46-
digitalWrite(in4, LOW);
47+
digitalWrite(in1Pin, HIGH);
48+
digitalWrite(in2Pin, LOW);
49+
digitalWrite(in3Pin, HIGH);
50+
digitalWrite(in4Pin, LOW);
4751
}
4852

49-
// Bot moves backwards
53+
// Function to move the bot backward
5054
void moveBackward() {
51-
digitalWrite(in1, LOW);
52-
digitalWrite(in2, HIGH);
53-
digitalWrite(in3, LOW);
54-
digitalWrite(in4, HIGH);
55+
digitalWrite(in1Pin, LOW);
56+
digitalWrite(in2Pin, HIGH);
57+
digitalWrite(in3Pin, LOW);
58+
digitalWrite(in4Pin, HIGH);
5559
}
5660

57-
// Bot turns left
61+
// Function to turn the bot left
5862
void moveLeft() {
59-
digitalWrite(in1, LOW);
60-
digitalWrite(in2, HIGH);
61-
digitalWrite(in3, HIGH);
62-
digitalWrite(in4, LOW);
63+
digitalWrite(in1Pin, LOW);
64+
digitalWrite(in2Pin, HIGH);
65+
digitalWrite(in3Pin, HIGH);
66+
digitalWrite(in4Pin, LOW);
6367
}
6468

65-
// Bot turns right
69+
// Function to turn the bot right
6670
void moveRight() {
67-
digitalWrite(in1, HIGH);
68-
digitalWrite(in2, LOW);
69-
digitalWrite(in3, LOW);
70-
digitalWrite(in4, HIGH);
71+
digitalWrite(in1Pin, HIGH);
72+
digitalWrite(in2Pin, LOW);
73+
digitalWrite(in3Pin, LOW);
74+
digitalWrite(in4Pin, HIGH);
7175
}
7276

73-
// Bot stops moving
77+
// Function to stop the bot
7478
void stopMoving() {
75-
digitalWrite(in1, LOW);
76-
digitalWrite(in2, LOW);
77-
digitalWrite(in3, LOW);
78-
digitalWrite(in4, LOW);
79-
}
79+
digitalWrite(in1Pin, LOW);
80+
digitalWrite(in2Pin, LOW);
81+
digitalWrite(in3Pin, LOW);
82+
digitalWrite(in4Pin, LOW);
83+
}

0 commit comments

Comments
 (0)