-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathac_control.ino
94 lines (70 loc) · 3.17 KB
/
ac_control.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
#include <avr/pgmspace.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
DHT_Unified dht(2, DHT22);
int IRledPin = 7;
unsigned int displayInt;
//String flag = "wait_up_edge";
//String flag = "wait_low_edge";
String flag = "wait_low_edge";
void setup(){
pinMode(IRledPin, OUTPUT);
dht.begin();
sensor_t sensor;
Serial.begin(9600);
}
//RAW buttons data
const int on_off[] PROGMEM = {9440, 4640,640, 1700,660, 1700,640, 540,640, 560,640, 540,640, 540,640, 540,640, 1720,640, 540,640, 1720,640, 1700,640, 560,640, 540,640, 540,640, 540,640, 560,640, 1700,640, 1720,640, 1700,640, 560,640, 540,640, 540,640, 540,640, 560,640, 540,640, 1700,640, 540,660, 540,640, 1700,660, 540,640, 540,640, 560,640, 520,660, 520,660, 540,640, 540,640, 560,640, 540,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 560,620, 560,640, 540,640, 540,640, 8300,640, 540,640, 540,640, 540,660, 520,660, 540,640, 540,640, 540,660, 520,660, 540,640, 540,640, 540,640, 540,660, 520,660, 540,640, 540,640, 540,640, 560,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 560,640, 540,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 540,640, 560,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 540,640, 540,660, 540,640, 540,640, 540,640, 540,660, 520,660, 600,640, 1700,640, 560,620, 1720,640, 540,660, 1700,640, 540,640, 540,640, 560,640};
void loop()
{
delay(2000);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)==false) {
Serial.print(F("t"));
Serial.print(event.temperature);
Serial.print(" ");
Serial.println(flag);
if (event.temperature < 20 )
{
if (flag == "wait_low_edge")
{
Serial.println("flag is wait_low_edge");
send_data(on_off, sizeof(on_off) / sizeof(on_off[0]));
flag = "wait_up_edge";
Serial.println("flag set wait_up_edge");
}
}
if (event.temperature > 23 )
{
if (flag == "wait_up_edge")
{
Serial.println("flag is wait_up_edge");
send_data(on_off, sizeof(on_off) / sizeof(on_off[0]));
flag = "wait_low_edge";
Serial.println("flag set wait_low_edge");
}
}
}
}
void pulse(long microsecs) {
cli();
while (microsecs > 0)
{ // 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working
microsecs -= 26; // so 26 microseconds altogether
} sei();
}
//send data by IR
void send_data(int IRsignal[], int size){
Serial.println("Sending IR signal");
for (int k = 0; k < size; k=k+2)
{
pulse(pgm_read_word_near(IRsignal + k));
delayMicroseconds(pgm_read_word_near(IRsignal + k+1));
};
}