#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 timer to 0
Tone tone1;
int oldS = 0;
int nbBoucle = 0;
const int pinWriteDefused = 2;
const int pinWriteBoom = 3;
const int pinReadDefused = 4;
const int pinReadBoom = 5;
char password[10]; // number of characters in our password
int currentLength = 0; //defines which number we are currently writing
int i = 0;
char entered[10];
int passwordLength;
int nbtry = 3;
int currentTry = nbtry;
const int Buzzer = 6;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
//Pour les keypad avec la fiche de connection vers le HAUT du clavier :
//byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
//byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
//Pour les keypad avec la fiche de connection vers le BAS du clavier :
byte rowPins[ROWS] = {13, 12, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7}; //connect to the column pinouts of the keypad
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()
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(2, 0 );
lcd.print( "Bombe Factice" );
lcd.setCursor( 2, 1 );
lcd.print( "BONNE PARTIE" );
delay(2000);
lcd.setCursor( 2, 0 );
lcd.print( "Bombe Factice" );
lcd.setCursor( 2, 1 );
lcd.print( "PAINTBALL MEDIO" );
delay(2000);
lcd.clear();
int hours, minutes, seconds;
lcd.begin(16, 2);
Serial.begin(9600);
tone1.begin(Buzzer);
//pinMode(Buzzer, OUTPUT);
//digitalWrite(Buzzer, LOW);
char key;
boolean cancel;
do
{
cancel = false;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time ?");
lcd.setCursor(4,1);
//Heures
hours = readHours();
if (hours == -1)
cancel = true;
else
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("Enter Code: ");
while ((currentLength < 1 || key != '#'))
{
lcd.setCursor(currentLength, 1);
lcd.cursor();
key = keypad.getKey();
if (key != NO_KEY)
{
buttonBip(100);
if (key != '#' && key != '*' && currentLength < 10)
{
lcd.print(key);
password[currentLength] = key;
++currentLength;
passwordLength = currentLength;
}
else if (key == '*')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Code: ");
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("Code: ");
boolean lec_code = true;
char code[10];
int i = 0;
char key2;
while (lec_code == true)
{
timer();
key2 = keypad.getKey();
if (key2 != NO_KEY)
buttonBip(100);
if (key2 == '#' || i >= 10)
lec_code = false;
else if (key2 == '*')
{
currentLength = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Code: ");
}
else
if (key2 != NO_KEY && currentLength < 10)
{
entered[currentLength] = key2;
currentLength++;
delay(100);
lcd.noCursor();
lcd.setCursor(currentLength + 4, 0);
lcd.print(key2);
lcd.setCursor(currentLength + 5, 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("Wrong Password!");
buttonBip(100);
delay(200);
buttonBip(100);
--currentTry;
if (currentTry == 0)
Boom();
lcd.setCursor(0, 1);
lcd.print("Try : ");
lcd.print(currentTry);
delay(1500);
currentLength = 0;
}
}