/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
Pick one up today in the adafruit shop!
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
/* niq_ro ( http://nicuflorica.blogspot.ro ) case for Nokia 5110 LCD (PCD8544) - LPH 7366:
For module from China, you must connect like this:
* Pin 1 (RST) -> Arduino digital 6 (D6)
* Pin 2 (CE) -> Arduino digital 7 (D7)
* Pin 3 (DC) -> Arduino digital 5 (D5)
* Pin 4 (DIN) -> Arduino digital 4 (D4)
* Pin 5 (CLK) - Arduino digital 3 (D3)
* Pin 7 (LIGHT) -> +5V thru 56-100 ohms resistor (for permanent lights) or... other pin control
* Pin 8 (GND) -> GND1 or GND2
*/
// version 1.8
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS, RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);
#include <DHT.h>
#define DHTPIN A2 // what pin we're connected DHT11
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
static unsigned char PROGMEM picatura[] =
{ B0001000,
B0001000,
B0001000,
B0010100,
B0100010,
B0100010,
B0011100
};
void setup () {
Serial.begin(9600);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
display.clearDisplay();
// sensor DHT for humidity and temperature
dht.begin();
// Print a logo message to the LCD.
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.setCursor(24, 8);
display.print("& niq_ro");
display.setCursor(1, 24);
display.print("ceas-calendar");
display.setCursor(0, 32);
display.print("temp. & umidit");
display.setCursor(0, 40);
display.print("versiunea ");
display.setTextColor(WHITE, BLACK);
display.print("1.8");
display.display();
delay (5000);
display.clearDisplay();
Wire.begin();
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
RTC.begin();
// RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
int k1;
int ko;
void loop () {
DateTime now = RTC.now();
int h = dht.readHumidity();
int t = dht.readTemperature();
// need for display time
int zs = now.second()/10;
int us = now.second() - zs*10;
if (us > 2 )
{
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(0, 0);
{ if ( now.hour() < 10)
{
display.print(" ");
display.print(now.hour(), DEC);
}
else
{
display.print(now.hour(), DEC);
}
display.setCursor(20, 0);
display.print(":");
display.setCursor(28, 0);
if ( now.minute() < 10)
{
display.print("0");
display.print(now.minute(), DEC);
}
else
{
display.print(now.minute(), DEC);
}
display.setCursor(48, 0);
display.print(":");
display.setCursor(57, 0);
if ( now.second() < 10)
{
display.print("0");
display.print(now.second(), DEC);
}
else
{
display.print(now.second(), DEC);
}
}
}
else
{
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(16, 0);
if ( now.hour() < 10)
{
display.print(" ");
display.print(now.hour(), DEC);
}
else
{
// display.setCursor(16, 0);
display.print(now.hour(), DEC);
}
display.print(":");
if ( now.minute() < 10)
{
display.print("0");
display.print(now.minute(), DEC);
}
else
{
display.print(now.minute(), DEC);
}
display.print(":");
if ( now.second() < 10)
{
display.print("0");
display.print(now.second(), DEC);
}
else
{
display.print(now.second(), DEC);
}
display.setCursor(10, 8);
if ( now.day() < 10)
{
display.print("0");
display.print(now.day(), DEC);
}
else
{
display.print(now.day(), DEC);
}
display.print("/");
if ( now.month() < 10)
{
display.print("0");
display.print(now.month(), DEC);
}
else
{
display.print(now.month(), DEC);
}
display.print("/");
display.print(now.year(), DEC);
}
if (us < 5 )
{
display.setTextSize(4);
display.setTextColor(BLACK);
display.setCursor(0,20);
display.print(t);
display.setCursor(60,20);
display.print("C");
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(48,20);
display.print("o");
display.display();
}
else
{
display.setTextSize(4);
// display.setTextColor(WHITE, BLACK);
display.setCursor(0,20);
display.print(h);
/* display.setCursor(60,20);
display.print("H");
*/
// draw an empty glass
display.drawLine(60, 20, 60, 45, BLACK);
display.drawLine(61, 20, 61, 45, BLACK);
display.drawLine(60, 44, 80, 44, BLACK);
display.drawLine(60, 45, 80, 45, BLACK);
display.drawLine(79, 20, 79, 45, BLACK);
display.drawLine(80, 20, 80, 45, BLACK);
// display.display();
int hp = h/4;
for (int x = 0; x < hp+1; x++)
{
display.drawLine(60, 44-x, 80, 44-x, BLACK);
}
// draw drops water
display.drawBitmap(65, 20, picatura, 8, 8, 1);
display.drawBitmap(70, 26, picatura, 8, 8, 1);
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(48,20);
display.print("%");
display.display();
}
delay (500);
display.clearDisplay();
}