-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojeto_tcc.pde
106 lines (85 loc) · 2.79 KB
/
projeto_tcc.pde
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
95
96
97
98
99
100
101
102
103
104
105
106
// Incluindo bibliotecas
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS1302.h>
#include <SD.h>
#include <avr/pgmspace.h>
#include <EncodeBase64.h>
// Configurações
#include "config.h"
// Incluindo funções de uso
#include "func.h"
// Arduino Setup
void setup(){
Serial.begin(9600);
// Beginning the services
sensors.begin();
// Set led mode
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZ_PIN, OUTPUT);
/********************************************
* Inicializa o SD e carrega as configurações
*********************************************/
pinMode(W5100_PIN, OUTPUT);
digitalWrite(W5100_PIN, HIGH);
if (!sd_card.init(SPI_HALF_SPEED, SD_SS_PIN)) error("card failed!");
if (!sd_volume.init(&sd_card)) error("vol failed!");
if (!sd_root.openRoot(&sd_volume)) error("Root failed");
// Load Configurations
load_configuration();
/*********************************************
* DS18S20 - Thermometer
**********************************************/
// Thermometer address
sensors.getAddress(thermometer, 0);
// alarm when temp is high
sensors.setHighAlarmTemp(thermometer, max_temp);
// alarm when temp is low
sensors.setLowAlarmTemp(thermometer, min_temp);
// set alarm handle
sensors.setAlarmHandler(&alarm_handler);
/*********************************************
* DS1302 - RTC
*********************************************/
/* Initialize a new chip by turning off write protection and clearing the
clock halt flag. These methods needn't always be called. See the DS1302
datasheet for details. */
rtc.write_protect(false);
rtc.halt(false);
/* Make a new time object to set the date and time */
/* Tuesday, May 19, 2009 at 21:16:37. */
//Time t(2011, 11, 12, 15, 47, 40, 0);
/* Set the time and date on the chip */
//rtc.time(t);
// Inicializa o server
Ethernet.begin(mac, ip, gw, msk);
server.begin();
}
void loop(){
sensors.requestTemperatures();
sensors.processAlarms(); // Alarm
// If no sensor alarm, turn of LED and BUZZER
if ( !sensors.hasAlarm() ) {
digitalWrite(LED_PIN, LOW);
noTone(BUZZ_PIN);
}
// listen for incoming clients
Client client = server.available();
if ( client ) {
processing_request(client);
}
Time t = rtc.time();
if( t.sec == 0 && ( t.min % t_intval ) == 0 ){
if( sd_file.open(&sd_root, log_file, O_CREAT | O_WRITE | O_APPEND ) ) {
float current_temp = sensors.getTempCByIndex(0) - atof( error_c );
char buffer[25];
byte dec = abs(current_temp - ((byte)current_temp)) * 100;
sprintf(buffer, "%02d-%02d-%04d|%02d:%02d:%02d|%02d.%02d", t.date, t.mon, t.yr, t.hr, t.min, t.sec, (byte)current_temp, dec);
sd_file.println(buffer);
sd_file.close();
delay(500);
}
}
}