-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.h
88 lines (71 loc) · 2.31 KB
/
Robot.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
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
#ifndef CONSTANTE_H
#include "Constante.h"
#endif
class Robot{
public:
Robot(){
pinMode(MOTORPIN1, OUTPUT);
pinMode(MOTORPIN2, OUTPUT);
pinMode(ENABLEPIN1, OUTPUT);
pinMode(MOTORPIN3, OUTPUT);
pinMode(MOTORPIN4, OUTPUT);
pinMode(ENABLEPIN2, OUTPUT);
}
void move(short direction = 1,short vitesse = 200,float delai = 2){
//Vitesse
analogWrite(ENABLEPIN1, abs(vitesse));
analogWrite(ENABLEPIN2, abs(vitesse));
//Direction 1 Forward et 0 Backward
if(direction == 1){
digitalWrite(MOTORPIN2, LOW);
digitalWrite(MOTORPIN4, LOW);
digitalWrite(MOTORPIN1, HIGH);
digitalWrite(MOTORPIN3, HIGH);
}else{
digitalWrite(MOTORPIN2, HIGH);
digitalWrite(MOTORPIN1, LOW);
digitalWrite(MOTORPIN4, HIGH);
digitalWrite(MOTORPIN3, LOW);
}
if(delai != -1){
delay((int)(delai * 1000));
}
}
void turn(short direction = 1,short vitesseLeft = 200,short vitesseRight=200,float delai = 2){
//Vitesse
analogWrite(ENABLEPIN1, abs(vitesseLeft));
analogWrite(ENABLEPIN2, abs(vitesseRight));
//Stop freinage
//Direction 1 Right et 0 left
if(direction == 1){
digitalWrite(MOTORPIN1, HIGH);
digitalWrite(MOTORPIN2, LOW);
Serial.print("Avant M1");
digitalWrite(MOTORPIN3, LOW);
digitalWrite(MOTORPIN4, HIGH);
Serial.print("Avant M2");
}else{
digitalWrite(MOTORPIN1, LOW);
digitalWrite(MOTORPIN2, HIGH);
Serial.print("Arriere M1");
digitalWrite(MOTORPIN3, HIGH);
digitalWrite(MOTORPIN4, LOW);
Serial.print("Arriere M2");
}
if(delai != -1){
delay((int)(delai * 1000));
}
}
void stop(short delai = 2,short finale = 0){
digitalWrite(MOTORPIN1, LOW);
digitalWrite(MOTORPIN2, LOW);
digitalWrite(MOTORPIN3, LOW);
digitalWrite(MOTORPIN4, LOW);
if(delai != -1){
delay(delai * 1000);
}
if(finale == 1){
while(1==1);
}
}
};