-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotor.h
More file actions
48 lines (39 loc) · 908 Bytes
/
Copy pathmotor.h
File metadata and controls
48 lines (39 loc) · 908 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
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef _MOTOR_H
#define _MOTOR_H
#define L_PWM_PIN 10
#define L_DIR_PIN 16
#define R_PWM_PIN 9
#define R_DIR_PIN 15 //Activation Pins
class motor_c {
public:
motor_c();
void leftWheel(float power);
void rightWheel(float power);
};
motor_c::motor_c(){
pinMode( L_PWM_PIN, OUTPUT );
pinMode( L_DIR_PIN, OUTPUT );
pinMode( R_PWM_PIN, OUTPUT );
pinMode( R_DIR_PIN, OUTPUT );
}
void motor_c:: leftWheel(float power){
if (power >= 0){
digitalWrite( L_DIR_PIN, LOW );
}
else {
digitalWrite( L_DIR_PIN, HIGH );
}
power = abs(power);
analogWrite( L_PWM_PIN, power );
}
void motor_c::rightWheel(float power) {
if (power >= 0){
digitalWrite( R_DIR_PIN, LOW );
}
else{
digitalWrite( R_DIR_PIN, HIGH );
}
power = abs(power);
analogWrite( R_PWM_PIN, power );
}
#endif