/
MasterAndSend.ino
48 lines (42 loc) · 1.1 KB
/
MasterAndSend.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
//Send device number
int _isMaster = 0;
int _deviceList[] = {9, 9, 9, 9}; //max 4 devices , and initial 9
IRsend irsend;
void SendDeviceNumber(){
//int curDevice = GetDeviceId();
//send device number twice
for (int i = 0; i <2; i++)
{
//Serial.print( F("Sending device number: "));
//Serial.println(curDeviceNumber);
irsend.sendSony (curDeviceNumber, 12); //current device number
delay(100);
};
}
void CheckMaster()
{
//try to find from device list
int found = 0;
int minDeviceNo = 9;
for (int i = 0; i < 4; i++ ) {
if(_deviceList[i]== results.value){
//Serial.println("Device already received");
found = 1;
}
if(_deviceList[i] < minDeviceNo)
minDeviceNo = _deviceList[i];
}
if(found == 0) { //not found, add to the device list
for (int i = 0; i < 4; i++ ) {
if(_deviceList[i]== 9){
_deviceList[i] = results.value;
}
}
}
if(results.value < minDeviceNo){
_isMaster = 1;
//Serial.println("Master is " + _isMaster);
} else {
_isMaster = 0;
}
}