Add variants
This commit is contained in:
parent
fdd216d49a
commit
fa55c0a61d
70
src/main.cpp
70
src/main.cpp
@ -1,45 +1,35 @@
|
||||
#include <LiquidCrystal_I2C.h> // https://github.com/johnrickman/LiquidCrystal_I2C
|
||||
#include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <NTPClient.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "DHTesp.h" // https://github.com/beegee-tokyo/DHTesp
|
||||
|
||||
#define buzzerPin 15 // define buzzer connected pin
|
||||
#define dhtPin 2 // define dht connected pin
|
||||
#define dhtType DHTesp::DHT11 // Define dht sensor type
|
||||
const char *ssid = "";
|
||||
const char *password = "";
|
||||
|
||||
const char *ssid = ""; // Wifi SSID
|
||||
const char *password = ""; // Wifi Password
|
||||
const long utcOffsetInSeconds = 10800;
|
||||
|
||||
const long utcOffsetInSeconds = 10800; // Set your timezone 1 hour = 3600 second
|
||||
const char *ntpServerUrl = "pool.ntp.org";
|
||||
|
||||
bool executed = false;
|
||||
bool Fahrenheit = false; // If you want change temperature unit to Fahrenheit set true
|
||||
const char *ntpServerUrl = "pool.ntp.org"; // Set npt server url
|
||||
// https://www.ntppool.org/en/
|
||||
String weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||
|
||||
DHTesp dht;
|
||||
WiFiUDP ntpUDP;
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
NTPClient timeClient(ntpUDP, ntpServerUrl, utcOffsetInSeconds);
|
||||
|
||||
void lcdClockDate();
|
||||
void TempHum();
|
||||
void ringBuzzer();
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buzzerPin, OUTPUT);
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
WiFi.begin(ssid, password);
|
||||
dht.setup(dhtPin, dhtType);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Connecting to");
|
||||
lcd.setCursor(3, 1);
|
||||
int startPos = (16 - String(ssid).length()) / 2;
|
||||
lcd.setCursor(startPos, 1);
|
||||
lcd.print(ssid);
|
||||
}
|
||||
lcd.clear();
|
||||
@ -50,14 +40,13 @@ void loop()
|
||||
{
|
||||
timeClient.update();
|
||||
lcdClockDate();
|
||||
TempHum();
|
||||
ringBuzzer();
|
||||
delay(2000);
|
||||
}
|
||||
void lcdClockDate()
|
||||
{
|
||||
time_t epochTime = timeClient.getEpochTime();
|
||||
String formattedTime = timeClient.getFormattedTime().substring(0, 5);
|
||||
String weekDay = weekDays[timeClient.getDay()];
|
||||
struct tm *ptm = gmtime((time_t *)&epochTime);
|
||||
int monthDay = ptm->tm_mday;
|
||||
String currentMonth = (ptm->tm_mon + 1) < 10 ? "0" + String(ptm->tm_mon + 1) : String(ptm->tm_mon + 1);
|
||||
@ -67,40 +56,9 @@ void lcdClockDate()
|
||||
lcd.print(CurrentDate);
|
||||
lcd.setCursor(11, 0);
|
||||
lcd.print(formattedTime);
|
||||
}
|
||||
void TempHum()
|
||||
{
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
if (Fahrenheit)
|
||||
{
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(dht.toFahrenheit(temperature), 1) + char(223) + "F");
|
||||
lcd.setCursor(11, 1);
|
||||
lcd.print("%" + String(humidity, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(temperature, 1) + char(223) + "C");
|
||||
lcd.setCursor(11, 1);
|
||||
lcd.print("%" + String(humidity, 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ringBuzzer() // This function activates the buzzer only once per hour
|
||||
{
|
||||
int currentMinute = timeClient.getMinutes();
|
||||
if (currentMinute == 0 && executed == false)
|
||||
{
|
||||
digitalWrite(buzzerPin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(buzzerPin, LOW);
|
||||
executed = true;
|
||||
}
|
||||
if (currentMinute != 0)
|
||||
{
|
||||
executed = false;
|
||||
}
|
||||
lcd.print(" ");
|
||||
int startPos = (16 - weekDay.length()) / 2;
|
||||
lcd.setCursor(startPos, 1);
|
||||
lcd.print(weekDay);
|
||||
}
|
||||
|
106
src/temp-clock.txt
Normal file
106
src/temp-clock.txt
Normal file
@ -0,0 +1,106 @@
|
||||
#include <LiquidCrystal_I2C.h> // https://github.com/johnrickman/LiquidCrystal_I2C
|
||||
#include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include "DHTesp.h" // https://github.com/beegee-tokyo/DHTesp
|
||||
|
||||
#define buzzerPin 15 // define buzzer connected pin
|
||||
#define dhtPin 2 // define dht connected pin
|
||||
#define dhtType DHTesp::DHT11 // Define dht sensor type
|
||||
|
||||
const char *ssid = ""; // Wifi SSID
|
||||
const char *password = ""; // Wifi Password
|
||||
|
||||
const long utcOffsetInSeconds = 10800; // Set your timezone 1 hour = 3600 second
|
||||
|
||||
bool executed = false;
|
||||
bool Fahrenheit = false; // If you want change temperature unit to Fahrenheit set true
|
||||
const char *ntpServerUrl = "pool.ntp.org"; // Set npt server url
|
||||
// https://www.ntppool.org/en/
|
||||
|
||||
DHTesp dht;
|
||||
WiFiUDP ntpUDP;
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
NTPClient timeClient(ntpUDP, ntpServerUrl, utcOffsetInSeconds);
|
||||
|
||||
void lcdClockDate();
|
||||
void TempHum();
|
||||
void ringBuzzer();
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(buzzerPin, OUTPUT);
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
WiFi.begin(ssid, password);
|
||||
dht.setup(dhtPin, dhtType);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Connecting to");
|
||||
lcd.setCursor(3, 1);
|
||||
lcd.print(ssid);
|
||||
}
|
||||
lcd.clear();
|
||||
timeClient.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
timeClient.update();
|
||||
lcdClockDate();
|
||||
TempHum();
|
||||
ringBuzzer();
|
||||
delay(2000);
|
||||
}
|
||||
void lcdClockDate()
|
||||
{
|
||||
time_t epochTime = timeClient.getEpochTime();
|
||||
String formattedTime = timeClient.getFormattedTime().substring(0, 5);
|
||||
struct tm *ptm = gmtime((time_t *)&epochTime);
|
||||
int monthDay = ptm->tm_mday;
|
||||
String currentMonth = (ptm->tm_mon + 1) < 10 ? "0" + String(ptm->tm_mon + 1) : String(ptm->tm_mon + 1);
|
||||
int currentYear = ptm->tm_year - 100;
|
||||
String CurrentDate = String(monthDay) + "/" + String(currentMonth) + "/" + String(currentYear);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(CurrentDate);
|
||||
lcd.setCursor(11, 0);
|
||||
lcd.print(formattedTime);
|
||||
}
|
||||
void TempHum()
|
||||
{
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
if (Fahrenheit)
|
||||
{
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(dht.toFahrenheit(temperature), 1) + char(223) + "F");
|
||||
lcd.setCursor(11, 1);
|
||||
lcd.print("%" + String(humidity, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(temperature, 1) + char(223) + "C");
|
||||
lcd.setCursor(11, 1);
|
||||
lcd.print("%" + String(humidity, 1));
|
||||
}
|
||||
}
|
||||
|
||||
void ringBuzzer() // This function activates the buzzer only once per hour
|
||||
{
|
||||
int currentMinute = timeClient.getMinutes();
|
||||
if (currentMinute == 0 && executed == false)
|
||||
{
|
||||
digitalWrite(buzzerPin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(buzzerPin, LOW);
|
||||
executed = true;
|
||||
}
|
||||
if (currentMinute != 0)
|
||||
{
|
||||
executed = false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user