Arduino - Code:
//***************************************************//
// //
// Ceas cu Big Font - Slim - LCD2004 V-1, 2o21 //
// //
// https://crisselectronicprojects.blogspot.com/ //
// //
//***************************************************//
//~~~~~~~~~~~~~~~~~~~~~~~~~~ Biblioteci necesare ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "LiquidCrystal.h"; // Biblioteca LCD
#include "RTClib.h" // Biblioteca RTC-Ceas
//~~~~~~~~~~~~~~~~~~~~ Variabila pentru afisare luna ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const char* Months[] =
{"Dec", "Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Nov" };
//~~~~~~~~~~~~~~~~~~~~ Variabile pentru meniu Ceas ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int ora;
int minut;
int secunda;
int x = 0;
// cele 8 caractere care formează fiecare segment al numerelor personalizate
byte DN[8] = {B11111, B11011, B11011, B11011, B11011, B11011, B11011, B11011};
byte UP[8] = {B11011, B11011, B11011, B11011, B11011, B11011, B11011, B11111};
byte UN[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B00011, B00011};
byte CI[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B11111};
byte CN[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111};
byte LI[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B00011};
byte ON[8] = {B11111, B11011, B11011, B11011, B11011, B11011, B11011, B11111};
byte PC[8] = {0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00};
//~~~~~~~~~~~~~~~~~ Definire pini pentru conectare la LCD ~~~~~~~~~~~~~~~~~~~~~~~
LiquidCrystal lcd (12, //RS no digital 7
11, //EN no digital 6
5, //D4 no digital 5
4, //D5 no digital 4
3, //D6 no digital 3
2); //D7 no digital 2
//Tipul de DS folosit la RTC Ceas
// RTC_DS1307 RTC;
RTC_DS3231 RTC;
void setup()
{
lcd.begin(20, 4); // Initializare tip LCD 20x4 sau 16x4, 16x2
if (! RTC.begin()) {
Serial.println("Couldn't find RTC");
RTC.adjust(DateTime(__DATE__, __TIME__));
while (1);
}
//~~~~~~~~~~~~~~~~ Citire Valori din DS3231 pentru functionare ceas ~~~~~~~~~~~~~~
DateTime now = RTC.now();
now = RTC.now();
ora = now.hour();
minut = now.minute();
secunda = now.second();
//~~~~~~~~~~~~~~~~~ Crearea celor 8 caractere personalizate ~~~~~~~~~~~~~~~~~~~~~~
lcd.createChar(1, DN);
lcd.createChar(2, UP);
lcd.createChar(3, UN);
lcd.createChar(4, CI);
lcd.createChar(5, CN);
lcd.createChar(6, LI);
lcd.createChar(7, ON);
lcd.createChar(8, PC);
lcd.setCursor(0, 0);
lcd.print("CrissElectronic");
lcd.setCursor(0, 1);
lcd.print("Projects");
lcd.setCursor(6, 3);
lcd.print("Romania");
delay(3000);
lcd.clear();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void loop()
{
DateTime now = RTC.now();
now = RTC.now();
ora = now.hour();
minut = now.minute();
secunda = now.second();
x = 12;
afisare(ora / 10);
x = x + 1;
afisare(ora % 10);
x = x + 1;
custom2puncte();
x = x + 1;
afisare(minut / 10);
x = x + 1;
afisare(minut % 10);
x = x + 1;
custom2puncte();
x = x + 1;
afisare(secunda / 10);
x = x + 1;
afisare(secunda % 10);
// ~~~~~~~~~~~~~~~~~ Afisare DATA ziua/luna/anul ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lcd.setCursor(0, 0);
if (now.day() < 10)
lcd.print(' ');
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(Months[now.month()]);
lcd.print('/');
lcd.print(now.year(), DEC);
// ~~~~~~~~~~~~~~~~ Afisare Temperatua - senzor intern DS3231 ~~~~~~~~~~~~~~~~~~
lcd.setCursor(0, 3);
lcd.print("Temp: ");
lcd.print(RTC.getTemperature());
lcd.print("'C");
lcd.print(" ");
// ~~~~~~~~~~~~~~~ Afisare ziua din saptamana ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lcd.setCursor(1, 1);
int dayofweek = now.dayOfTheWeek();
switch (dayofweek) {
case 1:
lcd.print(" Luni ");
break;
case 2:
lcd.print(" Marti ");
break;
case 3:
lcd.print("Miercuri");
break;
case 4:
lcd.print(" Joi ");
break;
case 5:
lcd.print(" Vineri ");
break;
case 6:
lcd.print(" Sambata");
break;
case 0:
lcd.print("Duminica");
break;
}
} // End loop
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~ Crearea cifrelor personalizate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void custom0O() //
{ // ~~~~~~~~~~~~~~~~~~~ Cifra 0
lcd.setCursor(x, 0);
lcd.write(1);
lcd.setCursor(x, 1);
lcd.write(2);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 1
void custom1()
{
lcd.setCursor(x, 0);
lcd.write(3);
lcd.setCursor(x , 1);
lcd.write(3);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 2
void custom2()
{
lcd.setCursor(x, 0);
lcd.write(4);
lcd.setCursor(x, 1);
lcd.write(5);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 3
void custom3()
{
lcd.setCursor(x, 0);
lcd.write(4);
lcd.setCursor(x, 1);
lcd.write(4);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 4
void custom4()
{
lcd.setCursor(x, 0);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(6);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 5
void custom5()
{
lcd.setCursor(x, 0);
lcd.write(5);
lcd.setCursor(x, 1);
lcd.write(4);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 6
void custom6()
{
lcd.setCursor(x, 0);
lcd.write(5);
lcd.setCursor(x, 1);
lcd.write(7);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 7
void custom7()
{
lcd.setCursor(x, 0);
lcd.write(6);
lcd.setCursor(x , 1);
lcd.write(3);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 8
void custom8()
{
lcd.setCursor(x, 0);
lcd.write(7);
lcd.setCursor(x, 1);
lcd.write(7);
}
// ~~~~~~~~~~~~~~~~~~~ Cifra 9
void custom9()
{
lcd.setCursor(x, 0);
lcd.write(7);
lcd.setCursor(x, 1);
lcd.write(4);
}
// ~~~~~~~~~~~~~~~~~~~ Doua puncte
void custom2puncte()
{
lcd.setCursor(x, 0);
lcd.write(8);
lcd.setCursor(x, 1);
lcd.write(8);
}
// ~~~~~~~~~~~~~~~~ Subrutina de afisare a numerelor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void afisare(int numar)
{
switch (numar)
{
case 0:
custom0O();
break;
case 1:
custom1();
break;
case 2:
custom2();
break;
case 3:
custom3();
break;
case 4:
custom4();
break;
case 5:
custom5();
break;
case 6:
custom6();
break;
case 7:
custom7();
break;
case 8:
custom8();
break;
case 9:
custom9();
break;
}
}// ~~~~~~~~~~~~~~~~~~ Sfarsit Program ~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Excelent, Multumesc
RăspundețiȘtergereModificarile mele pt. IC2
RăspundețiȘtergere//~~~~~~~~~~~~~~~~~~~~~~~~~~ Biblioteci necesare ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include
#include // Biblioteca LCD
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
if (! RTC.begin()) {
Serial.println("Couldn't find RTC");
RTC.adjust(DateTime(__DATE__, __TIME__));
while (1);
}
Faine lucrari ai facut... Thx. Bafta in continuare...
RăspundețiȘtergereUse to I2C [20x4 LCD]
RăspundețiȘtergere- change 1:
------------------------------------------------------------------------------------------
#include // Biblioteca LCD
#include "RTClib.h" // Biblioteca RTC-Ceas // https://www.arduinolibraries.info/libraries/rt-clib
------------------------------------------------------------------------------------------
- change 2:
------------------------------------------------------------------------------------------
void setup()
{
lcd.begin(20, 4); // Initializare tip LCD 20x4 sau 16x4, 16x2
lcd.init();
lcd.backlight();
------------------------------------------------------------------------------------------