-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArdrinko.ino
68 lines (58 loc) · 1.43 KB
/
Ardrinko.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
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <stdint.h>
// Pin layout:
// A0: Temperature reading (from TMP36 probe)
// A1: Photo resistor (SEN-09088)
// A2: LED
// A3: Button
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xB8, 0x93 };
IPAddress ip(10, 5, 0, 10);
IPAddress remote_ip(10, 5, 0, 1);
EthernetUDP Udp;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
Udp.begin(54369);
analogWrite(A2, 0);
}
void loop() {
int32_t temp = getTemp();
int32_t door = getDoor();
Udp.beginPacket(remote_ip, 54369);
Udp.write((uint8_t*)&temp, sizeof(int32_t));
Udp.write((uint8_t*)&temp, sizeof(int32_t));
Udp.write((uint8_t*)&temp, sizeof(int32_t));
Udp.write((uint8_t*)&temp, sizeof(int32_t));
Udp.write((uint8_t*)&door, sizeof(int32_t));
Udp.endPacket();
if (analogRead(A3) == 1023) {
analogWrite(A2, 255);
delay(100);
analogWrite(A2, 0);
delay(100);
analogWrite(A2, 255);
delay(100);
analogWrite(A2, 0);
delay(100);
analogWrite(A2, 255);
delay(100);
analogWrite(A2, 0);
} else {
analogWrite(A2, 0);
}
delay(50);
}
float readVoltage(int pin) {
return analogRead(pin) * (5.0 / 1023.0);
}
int32_t getTemp() {
float voltage = readVoltage(A0);
// 0.75V at 25 deg Celcius, 0.01V change per deg Celcius
float temp = (100 * voltage) - 75;
return (int32_t)(temp * 100);
}
int32_t getDoor() {
return (int32_t)analogRead(A1) > 700;
}