-
Notifications
You must be signed in to change notification settings - Fork 0
/
irremote.ino
executable file
·65 lines (57 loc) · 2.05 KB
/
irremote.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
61
62
63
#define DEBUG true
#define DECODE_NEC
#define MAX_TIME 150
#define RECV_PIN 7
#define BAUDRATE 115200
#define LOG(message) if(DEBUG) Serial.println(message)
#include <Arduino.h>
#include <IRremote.hpp>
bool useSysVol = false;
unsigned long lastPressTime = millis();
void sendCommand(char* command, bool lockPressDown = false){
if (lockPressDown){
LOG("locked");
if (millis() - lastPressTime > MAX_TIME) Serial.println(command);
lastPressTime = millis();
}
else {
LOG("unlocked");
Serial.println(command);
}
}
void setup() {
Serial.begin(BAUDRATE);
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
Serial.print("Ready to receive IR signals of protocols: ");
printActiveIRProtocols(&Serial);
Serial.println(String("at pin " + String(RECV_PIN)));
}
void loop() {
if (IrReceiver.decode()){
if (IrReceiver.decodedIRData.protocol != UNKNOWN){
if (DEBUG) IrReceiver.printIRResultShort(&Serial);
switch (IrReceiver.decodedIRData.command) {
case 0x7 :
if (useSysVol) sendCommand("SYSVOLDOWN");
else sendCommand("VOLDOWN");
break;
case 0x9 :
if (millis() - lastPressTime > MAX_TIME) useSysVol = !useSysVol;
lastPressTime = millis();
LOG(useSysVol);
break;
case 0x15 :
if (useSysVol) sendCommand("SYSVOLUP");
else sendCommand("VOLUP");
break;
case 0x16 : sendCommand("FULLSCREEN", true); break;
case 0x40 : sendCommand("FASTF"); break;
case 0x43 : sendCommand("PLAY", true); break;
case 0x44 : sendCommand("REWIND"); break;
case 0x46 : sendCommand("CYCLEWIN", true); break;
default : break;
}
}
}
IrReceiver.resume();
}