#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Tone.h>
#include <Timer.h>
#define pound 14
Timer counter;
//LiquidCrystal lcd(A5,A4,A3,A2,A1,A0);
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
int DefuseTimer = 0; // set tempo 0
Tone tone1;
int oldS = 0;
int nbBoucle = 0;
const int ledGreen = 3;
const int ledRed = 4;
////////////////////////
const int pulsante = 5;
int val = 0;
////////////////////////
char password[10];
int currentLength = 0;
int i = 0;
char entered[10];
int passwordLength;
int nbtry = 1;
int currentTry = nbtry;
const int Buzzer = 2;
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
boolean b600s = true;
boolean b300s = true;
boolean b120s = true;
boolean b60s = true;
boolean b30s = true;
boolean b10s = true;
void setup ()
{
int hours, minutes, seconds;
lcd.begin(16, 2);
Serial.begin(9600);
tone1.begin(Buzzer);
pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
char key;
boolean cancel;
do
{
cancel = false;
lcd.clear();
lcd.setCursor(0,0);
buttonBip(100);
lcd.print("Sistema attivo");
digitalWrite(ledGreen, HIGH);
delay(500);
digitalWrite(ledGreen, LOW);
lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print ("S.tempo.");
if (counter.hours >= 10)
lcd.setCursor (8,1);
//Heures
hours = readHours();
if (hours == -1)
cancel = hours;
else
lcd.setCursor(10,1);
lcd.print(":");
//Minutes
if (cancel == false)
{
minutes = readMinutes();
if (minutes == -1)
cancel = true;
else
lcd.print(":");
}
//Secondes
if (cancel == false)
{
seconds = readSeconds();
if (seconds == -1)
cancel = true;
}
if (cancel == false)
{
do
key = keypad.waitForKey();
while (key != '#' && key != '*');
buttonBip(100);
if (key == '*')
cancel = true;
}
}
while (cancel == true);
delay (500);
counter.setTime(hours, minutes, seconds);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Inserire codice: ");
while ((currentLength < 1 || key != '#'))
{
lcd.setCursor(currentLength, 1);
//lcd.cursor();
key = keypad.getKey();
if (key != NO_KEY)
{
buttonBip(100);
if (key!='#' && key != '*' && currentLength < 8)
{
lcd.print(key);
password[currentLength] = key;
++currentLength;
passwordLength = currentLength;
}
else if (key == '*')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Inserire codice: ");
currentLength = 0;
passwordLength = currentLength;
}
}
}
//Serial.print("rad:bomb:planted");
delay(500);
lcd.clear();
currentLength = 0;
}
void loop()
{
timer();
currentLength = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Codice: ");
boolean lec_code = true;
char code[8];
int i = 0;
char key2;
while (lec_code == true)
{
timer();
key2 = keypad.getKey();
if (key2 != NO_KEY)
buttonBip(100);
if (key2 == '#' || i >= 8)
lec_code = false;
else if (key2 == '*')
{
currentLength = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Codice: ");
}
else
if (key2 != NO_KEY && currentLength < 8)
{
entered[currentLength] = key2;
currentLength++;
delay(100);
lcd.noCursor();
lcd.setCursor(currentLength + 7, 0);
lcd.print(key2);
lcd.setCursor(currentLength + 8, 0);
lcd.cursor();
}
}
boolean correct = true;
for (int j = 0; j < currentLength; ++j)
if (entered[j] != password[j])
correct = false;
if (correct == true && passwordLength == currentLength)
{
Defused();
}
else if (currentLength >= 1)
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Password Errata!");
buttonBip(100);
delay(300);
buttonBip(100);
--currentTry;
if (currentTry == 0)
Boom();
lcd.setCursor(0, 1);
lcd.print("Tentativo : ");
lcd.print(currentTry);
delay(1500);
currentLength = 0;
}
}
//--------------------------------- Timer --------------------------------
prima parte di codice privo di modifiche