-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJST_RC_CAR.ino
More file actions
93 lines (72 loc) · 1.95 KB
/
JST_RC_CAR.ino
File metadata and controls
93 lines (72 loc) · 1.95 KB
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
92
93
#include <ESP32Servo.h>
static const int drvPin = 25;
static const int strPin = 26;
Servo drv;
Servo str;
void setup()
{
Serial.begin(115200);
drv.attach(drvPin, 1000, 2000); // บอกช่วงชัดเจน
drv.writeMicroseconds(1500); // neutral
str.attach(strPin);
delay(3000); // arm ESC
str.write(75); // RIGHT - 125 | LEFT - 75
}
void loop()
{
// ===== เดินหน้า =====
Serial.println("Forward");
drv.writeMicroseconds(1700);
delay(3000);
str.write(75);
// ===== หยุด =====
drv.writeMicroseconds(1500);
delay(1000);
// ===== เบรก =====
Serial.println("Brake");
drv.writeMicroseconds(1300);
delay(1500);
str.write(100);
// ===== กลับ neutral =====
drv.writeMicroseconds(1500);
delay(1000);
// ===== ถอย =====
Serial.println("Reverse");
drv.writeMicroseconds(1300);
delay(3000);
str.write(125);
// ===== หยุด =====
drv.writeMicroseconds(1500);
delay(3000);
// for(int spd = 1500; spd <= 1700; spd++){
// drv.writeMicroseconds(spd);
// Serial.println(spd);
// delay(20);
// }
// for(int posDegrees = 75; posDegrees <= 125; posDegrees++) {
// str.write(posDegrees);
// Serial.println(posDegrees);
// delay(20);
// }
// for(int spd = 1700; spd >= 1500; spd--){
// drv.writeMicroseconds(spd);
// Serial.println(spd);
// delay(20);
// }
// delay(500);
// for(int spd = 1500; spd >= 1000; spd--){
// drv.writeMicroseconds(spd);
// Serial.println(spd);
// delay(20);
// }
// for(int posDegrees = 125; posDegrees >= 75; posDegrees--) {
// str.write(posDegrees);
// Serial.println(posDegrees);
// delay(20);
// }
// for(int spd = 1200; spd <= 1500; spd++){
// drv.writeMicroseconds(spd);
// Serial.println(spd);
// delay(20);
// }
}