-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR4Nak.ino
81 lines (73 loc) · 2.69 KB
/
IR4Nak.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// IR control a Nakamichi tapedeck with Arduino, TSOP4838 and Sony CamCorder remote
// URL: https://github.com/Arduino-IRremote/Arduino-IRremote/wiki/Receiving-with-the-IRremote-library
// - drive LED's, later drive FET/transistors
// - test boards: Uno(ok), Nano(??), ESPxx(??)
// - use expander (i2c mcp23008...)
// - add MQTT status/control?
#include <IRremote.h> // IRremote library v3.3.0
int RECV_PIN = 10; // IR sensor data-pin
int pulseDly = 230; // Pulse length in ms
#define pPlay 2 // DIN-pin: 3
#define pRew 3 // DIN-pin: 5
#define pFwd 4 // DIN-pin: 4
#define pStop 5 // DIN-pin: 1
#define pPauze 6 // DIN-pin: 2
#define pRec 7 // DIN-pin: 6 (DIN-pin: 8 -> +12V)
decode_results results;
void setup() {
Serial.begin(9600);
Serial.println("IR control for Nakamichi tapedeck with Arduino and TSOP4838...");
pinMode(pPlay, OUTPUT);
pinMode(pRew, OUTPUT);
pinMode(pFwd, OUTPUT);
pinMode(pStop, OUTPUT);
pinMode(pPauze, OUTPUT);
pinMode(pRec, OUTPUT);
// IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver, enable feedback LED, take LED feedback pin from the internal boards definition
IrReceiver.begin(RECV_PIN);
IrReceiver.enableIRIn(); // Start the receiver
}
void sendPulse(int pulsePin, int pulseDly) {
digitalWrite(pulsePin, HIGH); delay(pulseDly); digitalWrite(pulsePin, LOW);
Serial.println(pulsePin);
}
void loop() {
if (IrReceiver.decode()) // have we received an IR signal?
{
IrReceiver.printIRResultShort(&Serial); // usefull for IR debugging
translateIR();
IrReceiver.resume(); // continue receiving
}
}
void translateIR() { // takes action based on IR code received
switch (IrReceiver.decodedIRData.decodedRawData)
{
case 0x39A: Serial.println("Play...");
sendPulse(pPlay,pulseDly);
break;
case 0x39B: Serial.println("Rewind...");
sendPulse(pRew,pulseDly);
break;
case 0x39C: Serial.println("Forward...");
sendPulse(pFwd,pulseDly);
break;
case 0x398: Serial.println("Stop...");
sendPulse(pStop,pulseDly);
break;
case 0x399: Serial.println("Pauze...");
sendPulse(pPauze,pulseDly);
break;
case 0x3A3: Serial.println("Slow..."); break;
case 0x3DA: Serial.println("Display..."); break;
case 0x5C99: Serial.println("Start/stop...");
// sendPulse(pStartStop,pulseDly);
digitalWrite(pStartStop, HIGH); delay(250); digitalWrite(pStartStop, LOW);
break;
case 0x6C9A: Serial.println("T..."); break;
case 0x6C9B: Serial.println("W..."); break;
default:
Serial.println("Other button...");
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
}
delay(500); // Do not get immediate repeat
}