Professional Documents
Culture Documents
h>
//#include <avr/pgmspace.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#include "DHT.h"
// DHT & AM2302 library
// Data pin connected to AM2302
#define DHTPIN 2
#define DHTTYPE DHT22
// DHT 22 (AM2302)
5,
5,
4,
4,
4,
4,
4,
5,
4,
5,
5,
5,
5,
4,
2,
4,
2,
3,
4,
2,
4,
4,
4,
4,
4,
3,
4,
4,
3,
4,
4,
3,
5,
4,
4,
4,
4,
4,
4,
3,
4,
5,
5,
5,
4,
3,
3,
1,
3,
4,
};
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
float t, h ;
void setup()
{
m.init();
m.setIntensity(4);
// printString(msg);
Wire.begin();
RTC.begin();
dht.begin();
//Si quitamos el comentario de la linea siguiente, se ajusta la hora y la fecha
con la del ordenador
RTC.adjust(DateTime(__DATE__, __TIME__));
// POWERCYCLE del RTC para comprobar que funcione correctamente
pinMode(4,OUTPUT);
digitalWrite(4,LOW);
delay(10);
digitalWrite(4,HIGH);
delay(10);
}
void loop()
{
DateTime now = RTC.now();
if(now.second() < 05 ){
int it = (int)dht.readTemperature();
int ih = (int)dht.readHumidity();
sprintf( temp, " %uc%u ", it , ih );
printString(temp);
}
if(now.second() > 05 ) {
sprintf( time, "%02hhu:%02hhu:%02hhu", now.hour(), now.minute(), now.secon
d());
printString(time);
}
//delay(300);
}
void printString(char* s)
{
int col = 0;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s - 32;
memcpy_P(buffer, CH + 7*c, 7);
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}