-
Notifications
You must be signed in to change notification settings - Fork 0
/
dyson.cpp
78 lines (67 loc) · 1.24 KB
/
dyson.cpp
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
#include <Arduino.h>
#include "dyson.h"
DysonRemote::DysonRemote(int IRPin)
{
IR_pin = IRPin;
pinMode(IR_pin, OUTPUT);
}
void DysonRemote::power()
{
int code = getCode();
for (int i = 0; i < 5; i++) {
header();
if (1 == code) {
phase(1540, 760);
pause(1);
phase(5324, 2200);
pause(1);
phase(1560, 760);
pause(2);
phase(1540, 740);
pause(9);
phase(1540, 740);
pause(1);
} else {
pause(2);
phase(6064, 2200);
pause(1);
phase(1560, 740);
pause(2);
phase(1560, 760);
pause(11);
}
digitalWrite(IR_pin, LOW);
delay(40);
}
}
void DysonRemote::header()
{
phase(0, 2200);
pause(1);
phase(1580, 740);
pause(2);
phase(1540, 760);
pause(9);
}
void DysonRemote::phase(int lowTime, int highTime)
{
digitalWrite(IR_pin, LOW);
delayMicroseconds(lowTime);
digitalWrite(IR_pin, HIGH);
delayMicroseconds(highTime);
}
void DysonRemote::pause(int repeat)
{
for (int i = 0; i < repeat; i++) {
phase(800, 740);
}
}
// The remote use 3 codes for each button
// You cannot use a same code twice
int DysonRemote::getCode()
{
if (lastCodeUsed == 2) {
return lastCodeUsed = 1;
}
return lastCodeUsed = 2;
}