Hi everyone! As title say, i need help for my first little project, the "digital alarm clock".
I write a little code that show time (hh:mins:sec) and under a message say "HAVE A NICE DAY".
"What's the problem?", you think.
Instead of that message, i want show the date and, with a button, set the clock and the date.
I use yet two button for set minute and hour. I post the code, hoping that someone help, and suggest, me something helpful to improve my first project. Thanks.
#include <LCD.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //impostazione indirizzo del display e pin del display LCD
int sec,mins,ora;
char buf1[17];
int val1=0, val2=0;
int puls1=2, puls2=3;
void setup() {
lcd.begin(16,2); //Start the LCD I2C 16x2
pinMode(puls1, INPUT);
pinMode(puls2, INPUT);
}
void loop(){
lcd.clear();
for(ora=0; ora<24; ora++)
for(mins=0; mins<60; mins++)
for(sec=0; sec<60; sec++)
{
val1 = digitalRead(puls1);
val2 = digitalRead(puls2);
//set hours
if(val1==1){
lcd.clear();
sprintf(buf1, " %02d:%02d:%02d",ora++,mins,sec);
lcd.print(buf1);
lcd.setCursor(1,1);
lcd.print("HAVE A NICE DAY");
delay(100);}
//check hour
if(ora > 23){
ora = 0;
lcd.clear();
sprintf(buf1, " %02d:%02d:%02d",0,mins,sec);
lcd.print(buf1);
lcd.setCursor(1,1);
lcd.print("HAVE A NICE DAY");
delay(100);}
//set minutes
if(val2==1){
lcd.clear();
sprintf(buf1, " %02d:%02d:%02d",ora,mins++,sec);
lcd.print(buf1);
lcd.setCursor(1,1);
lcd.print("HAVE A NICE DAY");
delay(100);}
//check minutes
if(mins > 59){
mins = 0;
lcd.clear();
sprintf(buf1, " %02d:%02d:%02d",ora++,0,sec);
lcd.print(buf1);
lcd.setCursor(1,1);
lcd.print("HAVE A NICE DAY");
delay(100);}
//Show final result on LCD screen
lcd.setCursor(0, 0);
sprintf(buf1, " %02d:%02d:%02d",ora,mins,sec);
lcd.print(buf1);
lcd.setCursor(1,1);
lcd.print("HAVE A NICE DAY");
delay(1000); //Seconds
}
}
prova.ino (1.78 KB)