-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotDrive.cpp
More file actions
37 lines (31 loc) · 777 Bytes
/
RobotDrive.cpp
File metadata and controls
37 lines (31 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "RobotDrive.h"
#include <math.h>
#if ARDUINO > 22
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
RobotDrive::RobotDrive() {
pinMode(left_dir, OUTPUT);
pinMode(right_dir, OUTPUT);
pinMode(left_speed, OUTPUT);
pinMode(right_speed, OUTPUT);
}
void RobotDrive::tankDrive(int leftVal, int rightVal) {
if (leftVal < 0 ) {
leftVal = abs(leftVal);
digitalWrite(left_dir, BACKWARD);
analogWrite(left_speed, leftVal);
} else {
digitalWrite(left_dir, FORWARD);
analogWrite(left_speed, leftVal);
}
if (rightVal < 0) {
rightVal = abs(rightVal);
digitalWrite(right_dir, BACKWARD);
analogWrite(right_speed, rightVal);
} else {
digitalWrite(right_dir, FORWARD);
analogWrite(right_speed, rightVal);
}
}