forked from arifmandal/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IR_REMOTE_WITH_SERVO.ino
60 lines (48 loc) · 958 Bytes
/
IR_REMOTE_WITH_SERVO.ino
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
#include<IRremote.h>
#include<Servo.h>
const int RECV_PIN = 11;
const int SERVO_PIN = 9;
int pos = 90;
unsigned long sonKod;
IRrecv irrecv(RECV_PIN);
decode_results kod;
Servo servo;
void setup() {
// put your setup code here, to run once:
irrecv.enableIRIn();
servo.attach(SERVO_PIN);
servo.write(pos);
}
void loop() {
// put your main code here, to run repeatedly:
if (irrecv.decode(&kod)) {
if (kod.value == 0xFFA25D) {
kod.value = sonKod;
}
if (kod.value == 0xFF30CF) {
sonKod = kod.value;
pos += 25;
if (pos > 180) {
pos = 180;
}
servo.write(pos);
}
if (kod.value == 0xFF6897)
{
sonKod = kod.value;
pos -= 25;
if (pos < 0) {
pos = 0;
}
servo.write(pos);
}
if (kod.value == 0xFFE21D)
{
sonKod = kod.value;
pos = 90;
servo.write(pos);
}
delay(30);
irrecv.resume();
}
}