salve a tutti, rieccomi a chiedere di nuovo il vostro aiuto.
Dopo più di un mese di programmazione sono riuscito a far funzionare il tutto alla perfezione solamente volevo migliorare inserimento del timer in modo più pulito
in questo momento il timer ha durata massima 59 m e 59 secondi(non ha le ore)
quando vado ad inserire il tempo che deve scalare lo devo inserire in questo modo, ess: 1500 che equivale a 15:00 minuti(nella schermata di conferma lo vedo correttamente)
Qualcuno mi può suggerire dove devo intervenire sul codice per avere una cosa del genere H00:M00:S00
dove andrò a sostituire gli 0 con i valori impostati da tastiera, se è possibile volevo fare lampeggiare lo 0 che deve cambiare valore(mi pare che si faccia con lcd.cursor())
Il codice dovrebbe essere abbastanza chiaro...ovviamente ci saranno milioni di righe di codice che potranno essere semplificate xD(i consigli sono ben accetti)
/////////////////////////
// S.M.A.S. Softair //
// codice editato da //
// Fabio Tomaselli //
/////////////////////////
#include <Key.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
//LED e Buzzer
int buzzer = 12;
//settaggi timer
int currentTimeValue = 0;
char tempo[4];
int currentState = 1;
int timerSeconds = 0;
int lpcnt = 0;
//settaggi della password
int currentLength = 0 ;
char password[6];
char entered[6];
//settaggi tastiera
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'#', '0', '*', 'D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //pin delle righe
byte colPins[COLS] = {9, 8, 7, 6}; //in delle colonne
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x27, 16, 2);
void(* Riavvia) (void) = 0; //riavvio della valigetta
void setup() {
pinMode(buzzer, OUTPUT);
lcd.init();
Serial.begin(9600);
lcd.backlight(); // illumina il display
lcd.setCursor(4, 0);
lcd.print("S.M.A.S.");
lcd.setCursor(2, 1);
lcd.print("Loading");
lcd.setCursor(9, 1);
lcd.print(".");
delay(1000);
lcd.setCursor(10, 1);
lcd.print(".");
delay(1000);
lcd.setCursor(11, 1);
lcd.print(".");
delay(1000);
lcd.setCursor(12, 1);
lcd.print(".");
delay(1000);
lcd.setCursor(13, 1);
lcd.print(".");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Inserire Codice:");
while (currentLength < 6)
{
lcd.setCursor(currentLength + 5, 1);
lcd.cursor();
char key = keypad.getKey();
key == NO_KEY;
if (key != NO_KEY)
{
if ((key != '*') && (key != '#') && (key != 'A') && (key != 'B') && (key != 'C') && (key != 'D'))
{
lcd.print(key);
password[currentLength] = key;
currentLength++;
}
}
}
if (currentLength == 6)
{
delay(1500);
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Codice Inserito!");
lcd.setCursor(5, 1);
lcd.print(password[0]);
lcd.print(password[1]);
lcd.print(password[2]);
lcd.print(password[3]);
lcd.print(password[4]);
lcd.print(password[5]);
delay(3000);
lcd.clear();
currentLength = 0;
}
lcd.setCursor(0, 0);
lcd.print("Inserire Tempo:");
while (currentTimeValue < 4)
{
lcd.setCursor(currentTimeValue + 6, 1);
lcd.cursor();
char key = keypad.getKey();
key == NO_KEY;
if (key != NO_KEY)
{
if ((key != '*') && (key != '#') && (key != 'A') && (key != 'B') && (key != 'C') && (key != 'D')) //caratteri non permessi
{
lcd.print(key);
tempo[currentTimeValue] = key;
currentTimeValue++;
}
}
}
if (currentTimeValue == 4)
{
delay(1500);
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Tempo Inserito!");
lcd.setCursor(5, 1);
lcd.print(tempo[0]);
lcd.print(tempo[1]);
lcd.setCursor(7, 1);
lcd.print(':');
lcd.print(tempo[2]);
lcd.print(tempo[3]);
delay(3000);
lcd.clear();
currentTimeValue = 0;
}
}
void settaggiotempo() {
int l;
char tempVal[3];
char key = keypad.getKey();
if (currentState == 1) {
tempVal[0] = tempo[0];
tempVal[1] = tempo[1];
tempVal[2] = 0;
timerSeconds = atol(tempVal) * 60;
tempVal[0] = tempo[2];
tempVal[1] = tempo[3];
tempVal[2] = 0;
timerSeconds = timerSeconds + atol(tempVal);
currentState = 2;
}
if (lpcnt > 9) {
lpcnt = 0;
--timerSeconds;
tone(buzzer, 1500, 500);
countdown();
if (timerSeconds <= 0) {
currentState = 1;
lcd.clear();
tone(buzzer, 2000, 400);
delay(500);
tone(buzzer, 2000, 400);
delay(500);
tone(buzzer, 2000, 400);
delay(500);
tone(buzzer, 2000, 400);
delay(500);
tone(buzzer, 2000, 400);
delay(500);
lcd.setCursor(5, 0);
lcd.print("Bomba");
lcd.setCursor(4, 1);
lcd.print("Esplosa!");
delay(10000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Riavvio");
delay(1000);
lcd.setCursor(7, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(8, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(9, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(10, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(11, 0);
lcd.print(".");
delay(1000);
Riavvia();
}
}
++lpcnt;
delay(100);
}
void bombaesplosa() {
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Codice Errato!");
delay(5000);
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Bomba");
lcd.setCursor(4, 1);
lcd.print("Esplosa!");
delay(10000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Riavvio");
delay(1000);
lcd.setCursor(7, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(8, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(9, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(10, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(11, 0);
lcd.print(".");
delay(1000);
Riavvia();
}
void tempoimpostato() {
lcd.setCursor(7, 1);
lcd.print(tempo[0]);
lcd.print(tempo[1]);
lcd.print(":");
lcd.print(tempo[2]);
lcd.print(tempo[3]);
}
void countdown() {
char timest[6];
lcd.setCursor(0, 1);
lcd.print("Tempo: ");
sprintf(timest, "%.2d:%.2d", (timerSeconds / 60), (timerSeconds - ((timerSeconds / 60) * 60)));
lcd.print(timest);
}
void loop() {
int l;
char tempVal[3];
char key2 = keypad.getKey();
settaggiotempo();
// if (key2 == 'A') //premi per scrivere la pass
// {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Codice:");
while (currentLength < 6) //aspetta la password
{
settaggiotempo();
char key2 = keypad.getKey();
if (key2 == 'C') // premi x cancellare la pass
{
currentLength = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Codice:");
}
else if (key2 != NO_KEY)
{
lcd.setCursor(currentLength + 7, 0);
lcd.cursor();
lcd.print(key2);
entered[currentLength] = key2;
currentLength++;
delay(100);
lcd.noCursor();
lcd.setCursor(currentLength + 6, 0);
lcd.print("*");
lcd.setCursor(currentLength + 7, 0);
lcd.cursor();
}
}
if (currentLength == 6)
{
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3] && entered[4] == password[4] && entered[5] == password[5])
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.setCursor(5, 0);
lcd.print("Bomba");
lcd.setCursor(2, 1);
lcd.print("Disinnescata");
currentLength = 0;
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Riavvio");
delay(1000);
lcd.setCursor(7, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(8, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(9, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(10, 0);
lcd.print(".");
delay(1000);
lcd.setCursor(11, 0);
lcd.print(".");
delay(1000);
Riavvia();
}
else
{
bombaesplosa();
}
}
//}
}