-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControl_LinearActuator.c
More file actions
55 lines (50 loc) · 1.14 KB
/
Control_LinearActuator.c
File metadata and controls
55 lines (50 loc) · 1.14 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
// 핀 번호 정의
const int IN1 = 9;
const int IN2 = 10;
// 액추에이터 동작 상태 열거형
enum ActuatorState {
EXTEND, // 최대 길이로 늘림
RETRACT, // 최소 길이로 줄임
STOP // 정지
};
// 상태별 제어 함수
void controlActuator(ActuatorState state) {
switch (state) {
case EXTEND:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
break;
case RETRACT:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
break;
case STOP:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
break;
}
}
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
// 초기 전원 시에는 아무 동작도 하지 않는다.
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\\n');
cmd.trim();
if (cmd == "UP") {
// 최대 길이로 늘리고 정지
controlActuator(EXTEND);
delay(15000);
controlActuator(STOP);
}
else if (cmd == "DOWN") {
// 최소 길이로 줄이고 정지
controlActuator(RETRACT);
delay(15000);
controlActuator(STOP);
}
}
}