odometer:
@MrWilliam932:
Please post your entire sketch.
This is all the code (some variables are in spanish), this time the left.unixtime() tells me the correct time in seconds but i can't show it in minutes and seconds, I think its easy to resolve the code having the time in seconds.
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_Millis rtc;
LiquidCrystal_I2C lcd(0x27,16,2);
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String Tiempo = "00:00";
String Minutos ="00";
String Segundos ="00";
boolean Insolando = false;
byte menupos = 0;
byte TiempoCursor = 0;
byte MinutosIns = 0;
byte SegundosIns = 0;
byte Capas = 0;
char key;
boolean waitforconf = true;
boolean settime = false;
unsigned long endtime;
void setup() {
Serial.begin(9600);
Wire.begin();
lcd.init();
lcd.backlight();
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
lcd.print("Bienvenido");
delay(2000);
lcd.clear();
}
void loop() {
switch(Insolando){
case false:
//Programa de configuración
while(Insolando == false){
delay(200);
switch(menupos){
case 0:
lcd.setCursor(0,0);
lcd.print("Tiempo de Insol.");
lcd.setCursor(0,1);
lcd.print(Tiempo);
key = keypad.getKey();
if (key){
TiempoCursor = constrain(TiempoCursor,0,4);
if(TiempoCursor== 2){
TiempoCursor = 3;
}
if(key == '*'){
Minutos = Tiempo.substring(0,2);
MinutosIns = Minutos.toInt();
Segundos = Tiempo.substring(3);
SegundosIns = Segundos.toInt();
if(SegundosIns >= 60 || MinutosIns >= 60 || SegundosIns == 0 && MinutosIns == 0){
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Valor Incorrecto");
delay(1000);
Tiempo = "00:00";
TiempoCursor = 0;
menupos = 0;
lcd.clear();
break;
}
TiempoCursor = 0;
menupos = 1;
lcd.clear();
break;
}
else if(key == '#'){
Tiempo = "00:00";
TiempoCursor = 0;
menupos = 0;
lcd.clear();
break;
}
Tiempo.setCharAt(TiempoCursor, key);
TiempoCursor++;
}
break;
case 1:
lcd.setCursor(0,0);
lcd.print("Cara:1->Inf.");
lcd.setCursor(0,1);
lcd.print("2->Sup 3->Ambas");
key = keypad.getKey();
if (key){
lcd.clear();
if(key == '1'){
Capas = 1;
menupos = 2;
}
else if(key == '2'){
Capas = 2;
menupos = 2;
}
else if(key == '3'){
Capas = 3;
menupos = 2;
}
else if(key == '#'){
menupos = 0;
}
else{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Selecciona un");
lcd.setCursor(0,1);
lcd.print("valor correcto");
delay(2000);
lcd.clear();
menupos=1;
Capas = 0;
}
}
break;
case 2:
lcd.setCursor(0,0);
lcd.print(MinutosIns);
lcd.print(" Mins y ");
lcd.print(SegundosIns);
lcd.print(" Segs");
lcd.setCursor(0,1);
if(Capas == 1){
lcd.print("Capa Inferior");
}
else if (Capas == 2){
lcd.print("Capa Superior");
}
else if (Capas == 3){
lcd.print("Doble Capa");
}
delay(2500);
lcd.clear();
waitforconf = true;
while(waitforconf == true){
lcd.setCursor(0,0);
lcd.print("ACEPTAR?");
lcd.setCursor(0,1);
lcd.print("*->Si #->Atras");
key = keypad.getKey();
if (key){
lcd.clear();
if(key == '*'){
waitforconf = false;
Insolando = true;
break;
}
else if(key == '#'){
waitforconf = false;
menupos = 1;
}
}
}
break;
}
}
break;
lcd.clear();
case true:
while(Insolando == true){
DateTime now = rtc.now();
if(settime == false){
endtime = now.unixtime() + MinutosIns * 60 + SegundosIns;
settime = true;
}
DateTime left = endtime - now.unixtime();
Serial.println(left.unixtime(),DEC);
Serial.println(endtime);
Serial.println(now.unixtime());
lcd.clear();
lcd.setCursor(0,0);
lcd.print(left.minute());
lcd.print(':');
lcd.print(left.second());
// lcd.print("Insolando...");
// lcd.setCursor(0,1);
// lcd.print(left.minute());
// lcd.print(':');
// lcd.print(left.second());
//if(left.unixtime() == 0){
// settime = false;
// Tiempo = "00:00";
// Minutos ="00";
//Segundos ="00";
//Insolando = false;
//menupos = 0;
//TiempoCursor = 0;
//MinutosIns = 0;
//SegundosIns = 0;
//Capas = 0;
//waitforconf = true;
//break;
// }
delay(1000);
break;
}
}
}