Sie sind auf Seite 1von 9

/******************************************************************

* Author
: Hugo Gutierrez Salazar
*
* Release
: 2.9
*
* Soft.Date
: April 8-15th, 2014
*
* Fecha Nuevo Release : March 18th, 2015
*
* Comments
: Include date and buttons setting for
*
*
hours,minutes and seconds.
*
* Hardware Used : - Arduino Uno R-3 module
*
*
- Display LCD Arduino Compatible (LCD 16x2) *
*
- Display (Hitachi HD44780 driver).
*
*******************************************************************
* 18-MAR-2015 : Al cambiar de 31 de Enero, pasaba a 32 de Enero *
* FIX compartido
: Salvador Olmos (Puebla , Mexico)
*
*
y Hugo Gutierrez (Santiago, Chile)
*
*******************************************************************
* 18-MAR-2015 : NO cambia a 29 de Febrero en Ao Bisiesto (2020) *
* FIX
: Hugo Gutierrez (Santiago, Chile)
*
* Language Version : English.
*
******************************************************************/
// Include Liquid Crystal library
#include <LiquidCrystal.h>
#include <stdio.h>
// Initialize library with interface pin numbers
// Each LCD Display can use his how numbers.
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
// Global variable definitions.
int horas = 0;
int minutos = 0;
int segundos = 1;
// Settings to add date
char ST_DIA[] ="LUMAMIJUVISADO";
char ST_NOM_MES[] ="ENEFEBMARABRMAYJUNJULAGOSEPOCTNOVDIC";
char MES[]
char DIA[]

= "XXX";
= "XX";

int ST_MES[] = {31,28,31,30,31,30,31,31,30,31,30,31};


int MAX_DIAS_MES = 0;
int N_DIA

= 1;

int N_MES
= 1;
int i
; // Variable to contain day number
int j
= 1; // Variable to contain month number
int
int
int
int
int

ANO
= 2015;
Dia
= 1;
lcd_key = 0;
adc_key_in = 0;
ajuste
= 0; // 1 : Dia : LU ...DO
// 2 : Dia : 1....31
// 3 : Mes : ENE ...DIC
// 4 : AO : 2014 ....
// 5 : HORA : 0 .. 23
// 6 : Minutos : 0 .. 59

#define btnRIGHT 0 // (Second Adjust)


#define btnUP
1 // (Count increment)
#define btnDOWN
2 // (Count Decrement)
#define btnLEFT 3 // (Minutes Adjust)
#define btnSELECT 4 // (Hours Adjust)
#define btnNONE
5 // (None pressed)
int read_LCD_buttons()
{
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50 ) return btnRIGHT;
if (adc_key_in < 250 ) return btnUP;
if (adc_key_in < 450 ) return btnDOWN;
if (adc_key_in < 650 ) return btnLEFT;
if (adc_key_in < 850 ) return btnSELECT;
return btnNONE;
}
void setup() {
strncpy(DIA,&ST_DIA[0],2);
strncat(DIA,'\0',1);
strncpy(MES,&ST_NOM_MES[0],3);
strncat(MES,'\0',1);
// Define display column and row numbers.
lcd.begin(16,2);
// Sends the initial message to show in the display
lcd.setCursor(0,0);
lcd.print(" LU-01/ENE/2015 ");

}
void loop() {
// Iniciate seconds count.
segundos++;
delay(1000);
// Assign maximum number of days in the month
MAX_DIAS_MES = ST_MES[j-1];
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(1,0);
lcd.print(DIA); /* Dia de la semana LU .. DO */
lcd.setCursor(3,0);
lcd.print("-");
lcd.setCursor(4,0);
if ( Dia < 10 )
lcd.print("0");
lcd.print(Dia); /* Dia del mes 1 .. 31
*/
lcd.setCursor(6,0);
lcd.print("/");
lcd.setCursor(7,0);
lcd.print(MES); /* Mes ...ENE ... DIC
*/
lcd.setCursor(10,0);
lcd.print("/");
lcd.setCursor(11,0);
lcd.print(ANO); /* Ao
*/
lcd.setCursor(15,0);
lcd.print(" ");
// When count overflow 59 seconds, it must increment a minute.
if (segundos > 59 ){
minutos++;
segundos=0;
}
// When count overflow 59 minutes, it must increment an hour
if (minutos > 59 ){
horas++;
minutos = 0;
}

// When count overflows 23 hours , it must reset all to zero.


if (horas > 23 ){
horas = 0;
minutos = 0;
segundos = 0;
N_DIA++; // Incrementa da de la semana
Dia++;
// Incrementa el dia en 1
i=N_DIA;
strncpy(DIA,&ST_DIA[(i-1)*2],2);
DIA[2]='\0';
}
// Verifies if year is a leap year.
if ( N_MES == 2 ){
if (ANO % 4 == 0 && (ANO % 100 != 0 || ANO % 400 == 0 )){
MAX_DIAS_MES = 29;
}
}
// if number of day is greater than the days of that month
// increment months number
if (Dia > MAX_DIAS_MES){
Dia = 1;
N_MES++;
j = N_MES;
strncpy(MES,&ST_NOM_MES[(j-1)*3],3);
MES[3]='\0';
MAX_DIAS_MES=ST_MES[j-1];
}
// If year ends add a new year
if (N_MES > 12) {
N_MES = 1;
ANO++;
strcpy(MES,"ENE");
MES[3]='\0';
}

lcd.setCursor(0,1); // Iniciate in Col 0 Line 1


lcd.print(" "); // Erase 4 first columns
lcd.setCursor(4, 1);
if (horas < 10){

lcd.print("0");
}
lcd.print(horas);
lcd.print(":");
if (minutos < 10){
lcd.print("0");
}
lcd.print(minutos);
lcd.print(":");
if (segundos < 10){
lcd.print("0");
}
lcd.print(segundos);
lcd.print(" ");
// Verify if a button is being pressed
// to set date and time.
lcd_key=read_LCD_buttons();
switch(lcd_key)
{
case btnSELECT: //Set Variable to change
{
lcd.setCursor(0, 0); /* Linea 1 */
lcd.print("Setea
");
ajuste++;
lcd.setCursor(0, 1); /* Linea 2 */
if (ajuste == 1){
lcd.print("Dia : Lu .. Do ");
}
if (ajuste == 2) {
lcd.print("Dia : 01 .. 31 ");
}
if (ajuste == 3) {
lcd.print("Mes : ENE .. DIC");
}
if (ajuste == 4) {
lcd.print("Ano : 2015 ... ");
}
if (ajuste == 5) {
lcd.print("Hora : 00..23 ");
}
if (ajuste == 6) {
lcd.print("Minutos: 00..59 ");

}
if (ajuste > 6 ) {
ajuste = 1;
}
delay(1000);
break;
}
case btnUP: // Count Increment
{
lcd.setCursor(0,0);
lcd.print(" Seteando ");
if (ajuste == 1){
N_DIA++;
if (N_DIA > 7){
N_DIA = 1;
}
// Calculates the day of the week
i=N_DIA;
strncpy(DIA,&ST_DIA[(i-1)*2],2);
DIA[2]='\0';
lcd.setCursor(0,1);
lcd.print("Dia :
lcd.setCursor(6,1);
lcd.print(DIA);
}
if (ajuste == 2){
Dia++;
if (Dia > 31){
Dia = 1;
}
lcd.setCursor(0,1);
lcd.print("Dia :
lcd.setCursor(6,1);
lcd.print(Dia);

");

");

}
if (ajuste == 3){
N_MES++;
if (N_MES > 12){
N_MES = 1;
}
if (N_MES == 2 && Dia > 29)
Dia = 28;

// Calculates the name of the month


j = N_MES;
strncpy(MES,&ST_NOM_MES[(j-1)*3],3);
MES[3]='\0';
lcd.setCursor(0,1);
lcd.print("Mes :
lcd.setCursor(6,1);
lcd.print(MES);
}
if (ajuste == 4){
ANO++;
lcd.setCursor(0,1);
lcd.print("Ano :
lcd.setCursor(6,1);
lcd.print(ANO);

");

");

}
if (ajuste == 5){
horas++;
if (horas > 23)
horas = 0;
lcd.setCursor(0, 1);
lcd.print ("Horas : ");
lcd.setCursor(8, 1);
if (horas < 10)
lcd.print("0");
lcd.print(horas);
lcd.print(" ");
}
if (ajuste == 6 ){
minutos++;
if (minutos > 59 )
minutos = 0;
lcd.setCursor(0, 1);
lcd.print ("Minutos :
lcd.setCursor(9, 1);
if (minutos < 10)
lcd.print("0");
lcd.print(minutos);
}

");

break;
}
case btnDOWN: // Count decrement
{

lcd.setCursor(0,0);
lcd.print(" Seteando ");
if (ajuste == 1){
N_DIA--;
if (N_DIA < 1){
N_DIA = 7;
}
// Calculates the day of the week
i=N_DIA;
strncpy(DIA,&ST_DIA[(i-1)*2],2);
strncat(DIA,'\0',1);
lcd.setCursor(0,1);
lcd.print("Dia :
lcd.setCursor(6,1);
lcd.print(DIA);

");

}
if (ajuste == 2){
Dia--;
if (Dia < 1){
Dia = 31;
}
lcd.setCursor(0,1);
lcd.print("Dia :
lcd.setCursor(6,1);
lcd.print(Dia);

");

}
if (ajuste == 3){
N_MES--;
if (N_MES < 1){
N_MES = 12;
}
// Calculates the name of the month
j = N_MES;
strncpy(MES,&ST_NOM_MES[(j-1)*3],3);
strncat(MES,'\0',1);
lcd.setCursor(0,1);
lcd.print("Mes :
lcd.setCursor(6,1);
lcd.print(MES);
}
if (ajuste == 4){
ANO--;

");

if (ANO < 2015) {


ANO = 2015;
}
lcd.setCursor(0,1);
lcd.print("Ano :
lcd.setCursor(6,1);
lcd.print(ANO);

");

}
if (ajuste == 5){
horas--;
if (horas < 0)
horas = 23;
lcd.setCursor(0, 1);
lcd.print ("Horas :
lcd.setCursor(8, 1);
if (horas < 10)
lcd.print("0");
lcd.print(horas);
}
if (ajuste == 6 ){
minutos--;
if (minutos < 0 )
minutos = 59;
lcd.setCursor(0, 1);
lcd.print ("Minutos :
lcd.setCursor(9, 1);
if (minutos < 10)
lcd.print("0");
lcd.print(minutos);
}
break;
}
case btnNONE:
{
break;
}
} /* Switch end */
} /* loop() end */

");

");

Das könnte Ihnen auch gefallen