/*
Why the heart icon? Because I thought it was cool
and I want to use it in the future with some heartbeat sensor.
I needed to keep it somewhere and it was here. ;)
*/
//#include <dht.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#include <TinyRTClib.h>
RTC_DS1307 rtc;
#define LED_PIN PB1
//#define DHT22_PIN PB1
const unsigned char img_heart_small[] PROGMEM = {
0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00
};
const unsigned char img_heart_big[] PROGMEM = {
0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
};
void splash() {
oled.clear();
oled.setCursor(20, 1);
oled.print(F("TD Timer"));
oled.setCursor(20, 3);
oled.print(F("for Light control"));
oled.setCursor(20, 5);
oled.print(F("tanvir.daphedar"));
oled.setCursor(20, 7);
oled.print(F("@gmail.com"));
}
void heartBeat() {
static char big = 1;
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Update if 200ms passed
if ((currentTime - startTime) > 200) {
startTime = currentTime;
big = 1 - big;
if (big) {
oled.bitmap(20, 4, 37, 6, img_heart_big);
} else {
oled.bitmap(20, 4, 37, 6, img_heart_small);
}
}
}
void prepareDisplay() {
unsigned int i, k;
unsigned char ch[5];
oled.clear();
oled.begin();
oled.setCursor(01, 1);
oled.print(F("Automatic light ctrl"));
//oled.print(F("temperature|humidity"));
// oled.setCursor(57, 4);
// oled.print(F("24.0C"));
// oled.setCursor(57, 5);
// oled.print(F("40.0%"));
oled.bitmap(10, 5, 17, 2, img_heart_small);
}
//float getTemperature() {
// return DHT.temperature;
//}
//float getHumidity() {
// return DHT.humidity;
//}
void setup() {
// pinMode(DHT22_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// To clear all the memory
oled.clear();
oled.on();
splash();
delay(3000);
prepareDisplay();
oled.setCursor(57, 4);
oled.print(" ");
digitalWrite(LED_PIN, LOW);
oled.setCursor(57, 5);
oled.print("Light OFF");
}
void loop() {
DateTime now = rtc.now();
oled.setCursor(3, 2);
oled.print(now.year(), DEC);
oled.print('/');
oled.print(now.month(), DEC);
oled.print('/');
oled.print(now.day(), DEC);
oled.print(' ');
oled.print(now.hour(), DEC);
oled.print(':');
oled.print(now.minute(), DEC);
oled.print(':');
oled.print(now.second(), DEC);
oled.print(" - ");
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Checks 1 second passed
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
if (now.hour() == 11 && now.minute() == 44 && now.second() == 50)
{oled.setCursor(57, 5); oled.print(" "); digitalWrite(LED_PIN, HIGH); oled.setCursor(57, 4); oled.print("Light ON");}
if (now.hour() == 11 && now.minute() == 45 && now.second() == 10)
{oled.setCursor(57, 4); oled.print(" "); digitalWrite(LED_PIN, LOW); oled.setCursor(57, 5); oled.print("Light OFF");}
// Update temperature
//float temperature = getTemperature();
// Set cursor
// Print to display
//oled.print(temperature, 1);
}
heartBeat();
}