-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRRemoteControl.ino
48 lines (40 loc) · 894 Bytes
/
IRRemoteControl.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
#include <IRremote.h>
#include <Servo.h>
const long RIGHT_BUTTON = 0x20DF609F;
const long LEFT_BUTTON = 0x20DFE01F;
const long POWER_BUTTON = 0x20DF10EF;
const int LED_PIN = 6;
const int SERV_PIN = 9;
const int STEP = 10;
IRrecv irrecv(2);
Servo servo;
decode_results results;
boolean ledStatus = false;
int servAngle = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(SERV_PIN, OUTPUT);
irrecv.enableIRIn();
servo.attach(SERV_PIN);
servo.write(180);
}
void loop()
{
if (irrecv.decode(&results)) {
switch (results.value) {
case POWER_BUTTON:
ledStatus = !ledStatus;
digitalWrite(LED_PIN, ledStatus);
break;
case LEFT_BUTTON:
servAngle -= STEP;
servo.write(servAngle);
break;
case RIGHT_BUTTON:
servAngle += STEP;
servo.write(servAngle);
break;
}
irrecv.resume();
}
}