-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCMotorHBridge.h
44 lines (39 loc) · 1.15 KB
/
DCMotorHBridge.h
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
void MoveitMoveit(int PulseWidth, int A_channel, int B_channel, int INPUT_PIN){
// Saturate output at 255
if (PulseWidth>=255){
PulseWidth = 255;
}else if(PulseWidth<=-255){
PulseWidth = -255;
}
// decide directions based on PWM sign
if(PulseWidth >=0){
// if command is positive, go CCW/CW
digitalWrite(A_channel,HIGH);
digitalWrite(B_channel,LOW);
analogWrite(INPUT_PIN,PulseWidth);
}
else if(PulseWidth < 0){
// if it switches signs, go the other way
digitalWrite(A_channel,LOW);
digitalWrite(B_channel,HIGH);
analogWrite(INPUT_PIN,-PulseWidth);
}
}
void Freebird(int PWM, int PWM_pin, int DIR_pin){
if (PWM>=255){
PWM = 255;
}else if(PWM<=-255){
PWM = -255;
}
// decide directions based on PWM sign
if(PWM >=0){
// if command is positive, go CCW/CW
digitalWrite(DIR_pin,HIGH);
analogWrite(PWM_pin,PWM);
}
else if(PWM < 0){
// if it switches signs, go the other way
digitalWrite(DIR_pin,LOW);
analogWrite(PWM_pin,-PWM);
}
}