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 ;
5
5
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
10
14
11
15
void setup () {
12
16
// 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);
19
23
20
24
// Start the serial connection at 9600 Bauds
21
25
Serial.begin (9600 );
22
26
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);
26
30
}
27
31
28
32
void loop () {
29
- // Our debug code to prove that the bot is running
33
+ // Debug code to demonstrate the movement of the bot
30
34
moveForward ();
31
35
delay (6000 );
32
36
moveBackward ();
@@ -38,42 +42,42 @@ void loop() {
38
42
stopMoving ();
39
43
}
40
44
41
- // Bot moves forward
45
+ // Function to move the bot forward
42
46
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);
47
51
}
48
52
49
- // Bot moves backwards
53
+ // Function to move the bot backward
50
54
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);
55
59
}
56
60
57
- // Bot turns left
61
+ // Function to turn the bot left
58
62
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);
63
67
}
64
68
65
- // Bot turns right
69
+ // Function to turn the bot right
66
70
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);
71
75
}
72
76
73
- // Bot stops moving
77
+ // Function to stop the bot
74
78
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