forked from WRO-2021/Cassiopea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motors.cpp
81 lines (67 loc) · 1.56 KB
/
motors.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "motors.h"
void motor_init()
{
pinMode(MOTOR_A1, OUTPUT);
pinMode(MOTOR_A2, OUTPUT);
pinMode(MOTOR_APWM, OUTPUT);
pinMode(MOTOR_B1, OUTPUT);
pinMode(MOTOR_B2, OUTPUT);
pinMode(MOTOR_BPWM, OUTPUT);
motor_stop();
motor_set_speed_both(127);
}
void motor_set_speed_both(uint8_t vel)
{
analogWrite(MOTOR_APWM, MOTOR_A_MULTIPLIER*vel);
analogWrite(MOTOR_BPWM, MOTOR_B_MULTIPLIER*vel);
}
void motor_set_speed_A(uint8_t vel)
{
analogWrite(MOTOR_APWM, MOTOR_A_MULTIPLIER*vel);
}
void motor_set_speed_B(uint8_t vel)
{
analogWrite(MOTOR_BPWM, MOTOR_B_MULTIPLIER*vel);
}
void motor_straight()
{
digitalWrite(MOTOR_A1, LOW);
digitalWrite(MOTOR_A2, HIGH);
digitalWrite(MOTOR_B1, LOW);
digitalWrite(MOTOR_B2, HIGH);
}
void motor_right()
{
digitalWrite(MOTOR_A1, HIGH);
digitalWrite(MOTOR_A2, LOW);
digitalWrite(MOTOR_B1, LOW);
digitalWrite(MOTOR_B2, HIGH);
}
void motor_left()
{
digitalWrite(MOTOR_A1, LOW);
digitalWrite(MOTOR_A2, HIGH);
digitalWrite(MOTOR_B1, HIGH);
digitalWrite(MOTOR_B2, LOW);
}
void motor_backward()
{
digitalWrite(MOTOR_A1, HIGH);
digitalWrite(MOTOR_A2, LOW);
digitalWrite(MOTOR_B1, HIGH);
digitalWrite(MOTOR_B2, LOW);
}
void motor_stop()
{
digitalWrite(MOTOR_A1, LOW);
digitalWrite(MOTOR_A2, LOW);
digitalWrite(MOTOR_B1, LOW);
digitalWrite(MOTOR_B2, LOW);
}
void motor_break()
{
digitalWrite(MOTOR_A1, HIGH);
digitalWrite(MOTOR_A2, HIGH);
digitalWrite(MOTOR_B1, HIGH);
digitalWrite(MOTOR_B2, HIGH);
}