-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEMAR-RCR.ino
127 lines (117 loc) · 3.25 KB
/
EMAR-RCR.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Project: Peter Moss COVID-19 AI Research Project
Repository: EMAR Mini, Emergency Assistance Robot
Author: Adam Milton-Barker (AdamMiltonBarker.com)
Contributors:
Title: EMAR Mini Remote Control Receiver
Description: The EMAR Mini Remote Control Receiver receives
IR commands and sends them to the iotJumpWay via
the EMAR Mini Remote Control iotJumpWay Publisher.
License: MIT License
Last Modified: 2020-07-13
Credit: Based on example code from www.elegoo.com
*/
#include <ArduinoJson.h>
#include "IRremote.h"
#include "IR.h"
IRrecv irrecv(RECEIVER);
decode_results results;
String deviceID = "";
void setup() {
Serial.begin(9600);
Serial.println("EMAR Mini Remote Control Receiver");
irrecv.enableIRIn();
}
void send_communication(String cTypeR, String cValR, String cMessageR)
{
String jsonString = "{\"From\":\""+deviceID+"\",\"Type\":\""+cTypeR+"\",\"Value\": \""+cValR+"\",\"Message\": \""+cMessageR+"\"}";
char charBuff[89];
jsonString.toCharArray(charBuff, 89);
Serial.println(jsonString);
}
void loop()
{
int tmpValue;
if (irrecv.decode(&results))
{
for (int i = 0; i < 23; i++)
{
if ((keyValue[i] == results.value) && (i<KEY_NUM))
{
String aVal = keyBuf[i];
String cType = "";
String cVal = "";
String cMessage = "";
if(aVal=="VOL+")
{
cType = "Head";
cVal = "UP";
cMessage = "Move Head UP";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="VOL-")
{
cType = "Head";
cVal = "DOWN";
cMessage = "Move Head DOWN";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="FAST FORWADOWN")
{
cType = "Head";
cVal = "RIGHT";
cMessage = "Move Head RIGHT";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="FAST BACK")
{
cType = "Head";
cVal = "LEFT";
cMessage = "Move Head LEFT";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="PAUSE")
{
cType = "Head";
cVal = "CENTER";
cMessage = "Move Head CENTER";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="UP")
{
cType = "Arm";
cVal = "UP";
cMessage = "Move Arm 1 UP";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="DOWN")
{
cType = "Arm";
cVal = "DOWN";
cMessage = "Move Arm 1 DOWN";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="2")
{
cType = "Arm";
cVal = "2UP";
cMessage = "Move Arm 2 UP";
send_communication(cType, cVal, cMessage);
}
else if(aVal=="5")
{
cType = "Arm";
cVal = "2DOWN";
cMessage = "Move Arm 2 DOWN";
send_communication(cType, cVal, cMessage);
}
tmpValue = results.value;
}
else if(REPEAT==i)
{
results.value = tmpValue;
}
}
irrecv.resume(); // receive the next value
}
}