-
Notifications
You must be signed in to change notification settings - Fork 0
/
aircleaner.ino
61 lines (52 loc) · 1.24 KB
/
aircleaner.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
#define IRLEDpin D2
// IR Codes in (ADDR1 | ADDR2 | COMMAND1 | COMMAND2) format?
unsigned long IRCODE_OFF = 0b01010101000001000000000000000100;
unsigned long IRCODE_LOW = 0b01010101000001110000001100000100;
unsigned long IRCODE_MEDIUM = 0b01010101000001100000001100000101;
unsigned long IRCODE_HIGH = 0b01010101000001010000001100000110;
// This routine runs only once upon reset
void setup() {
pinMode(IRLEDpin, OUTPUT);
Spark.function("acfanspeed", setFanSpeed);
}
void IRcarrier(unsigned int IRTime)
{
for(unsigned int i = 0; i < (IRTime / 26); i++)
{
digitalWrite(IRLEDpin, HIGH);
delayMicroseconds(11);
digitalWrite(IRLEDpin, LOW);
delayMicroseconds(11);
}
}
void IRsendCode(unsigned long code)
{
for (int i = 0; i < 32; i++)
{
if (code & 0x80000000) {
IRcarrier(1300);
} else {
IRcarrier(620);
}
code<<=1;
delayMicroseconds(1200);
}
}
int setFanSpeed(String speed)
{
if (speed == "OFF") {
IRsendCode(IRCODE_OFF);
} else if (speed == "LOW") {
IRsendCode(IRCODE_LOW);
} else if (speed == "MEDIUM") {
IRsendCode(IRCODE_MEDIUM);
} else if (speed == "HIGH") {
IRsendCode(IRCODE_HIGH);
} else {
// ignore
return -1;
}
return 0;
}
void loop() {
}