-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
91 lines (82 loc) · 2.06 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
#include "Arduino.h"
#include "EYRC_MOTION.h"
#define Motor_La 22
#define Motor_Lb 23
#define Motor_Ra 25
#define Motor_Rb 24
#define Motor_PWM_L 46
#define Motor_PWM_R 45
#define PWM 128
#define LCD_RW 36
EYRC_MOTION::EYRC_MOTION()
{
pinMode(Motor_La,OUTPUT);
pinMode(Motor_Lb,OUTPUT);
pinMode(Motor_Ra,OUTPUT);
pinMode(Motor_Rb,OUTPUT);
pinMode(Motor_PWM_L,OUTPUT);
pinMode(Motor_PWM_R,OUTPUT);
}
void EYRC_MOTION::moveForward(int pwm)
{
digitalWrite(Motor_La,LOW);
digitalWrite(Motor_Lb,HIGH);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,LOW);
digitalWrite(Motor_Rb,HIGH);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::moveBackward(int pwm)
{
digitalWrite(Motor_La,HIGH);
digitalWrite(Motor_Lb,LOW);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,HIGH);
digitalWrite(Motor_Rb,LOW);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::left_slow(int pwm)
{
digitalWrite(Motor_La,HIGH);
digitalWrite(Motor_Lb,HIGH);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,LOW);
digitalWrite(Motor_Rb,HIGH);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::left_sharp(int pwm)
{
digitalWrite(Motor_La,HIGH);
digitalWrite(Motor_Lb,LOW);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,LOW);
digitalWrite(Motor_Rb,HIGH);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::right_slow(int pwm)
{
digitalWrite(Motor_La,LOW);
digitalWrite(Motor_Lb,HIGH);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,HIGH);
digitalWrite(Motor_Rb,HIGH);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::right_sharp(int pwm)
{
digitalWrite(Motor_La,LOW);
digitalWrite(Motor_Lb,HIGH);
analogWrite(Motor_PWM_L,pwm);
digitalWrite(Motor_Ra,HIGH);
digitalWrite(Motor_Rb,LOW);
analogWrite(Motor_PWM_R,pwm);
}
void EYRC_MOTION::brake()
{
digitalWrite(Motor_La,HIGH);
digitalWrite(Motor_Lb,HIGH);
analogWrite(Motor_PWM_L,255);
digitalWrite(Motor_Ra,HIGH);
digitalWrite(Motor_Rb,HIGH);
analogWrite(Motor_PWM_R,255);
}