// Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
// Arduino Airsoft Time Bomb
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //Change the HEX address
//int ledPin1 = 6;
//int boutonPin1 = 11;
//int ledPin2 = 7;
//int boutonPin2 = 12;
//int BP_reset = 13;
int etat_bouton1;
int etat_bouton2;
int reset;
int Hours = 00;
int Minutes = 00;
int Seconds = 00;
int trycount = 0;
int keycount = 0;
int i = 0;
int redled = A2;
int yellowled = A1;
int greenled = A3;
int hourstenscode;
int hoursonescode;
int mintenscode;
int minonescode;
int sectenscode;
int seconescode;
long secMillis = 0;
long interval = 1000;
char password[4];
char entered[4];
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] = {9, 8, 7, 6}; //7,2,3,5 for Black 4x3 keypad
byte colPins[COLS] = {5, 4, 3, 2}; //6,8,4 for Black 4x3 Keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(redled, OUTPUT);
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
digitalWrite(redled,HIGH);
digitalWrite(yellowled,HIGH);
digitalWrite(greenled,HIGH);
lcd.init();
lcd.backlight();
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bomba ARDUBA");
if (keycount == 11);
{
Hours = (0 * 10) + 1;
Minutes = (0 * 10) + 0;
Seconds = (0 * 10) + 0;
delay(10);
lcd.noBlink();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Timer set at:");
if (Hours >= 10)
{
lcd.setCursor (7, 1);
lcd.print (Hours);
}
if (Hours < 10)
{
lcd.setCursor (7, 1);
lcd.write ("0");
lcd.setCursor (8, 1);
lcd.print (Hours);
}
lcd.print (":");
if (Minutes >= 10)
{
lcd.setCursor (10, 1);
lcd.print (Minutes);
}
if (Minutes < 10)
{
lcd.setCursor (10, 1);
lcd.write ("0");
lcd.setCursor (11, 1);
lcd.print (Minutes);
}
lcd.print (":");
if (Seconds >= 10)
{
lcd.setCursor (13, 1);
lcd.print (Seconds);
}
if (Seconds < 10)
{
lcd.setCursor (13, 1);
lcd.write ("0");
lcd.setCursor (14, 1);
lcd.print (Seconds);
}
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("sve spremno");
delay (500);
keycount = 12;
}
while (keycount == 12)
{
tone(10, 5000, 100);
delay(50);
tone(10, 0, 100);
delay(50);
tone(10, 5000, 100);
delay(50);
tone(10, 0, 100);
delay(50);
tone(10, 5000, 100);
delay(50);
tone(10, 0, 100);
lcd.clear();
lcd.print ("Bomb Armed!");
lcd.setCursor(0, 1);
lcd.print("Countdown start");
delay(3000);
lcd.clear();
keycount = 0;
}
}
void loop()
{
// etat_bouton1 = digitalRead(boutonPin1);
// etat_bouton2 = digitalRead(boutonPin2);
// reset = digitalRead(BP_reset);
timer();
char disarmcode = keypad.getKey();
if (etat_bouton1 == HIGH)
{
}
if (disarmcode == '*')
{
tone(10, 5000, 100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Code: ");
while (keycount < 4)
{
timer();
char disarmcode = keypad.getKey();
if (disarmcode == '#')
{
tone(10, 5000, 100);
keycount = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Code: ");
}
else if (disarmcode != NO_KEY)
{
lcd.setCursor(keycount + 7, 0);
lcd.blink();
lcd.print(disarmcode);
entered[keycount] = disarmcode;
keycount++;
tone(10, 5000, 100);
delay(100);
lcd.noBlink();
lcd.setCursor(keycount + 6, 0);
lcd.print("*");
lcd.setCursor(keycount + 7, 0);
lcd.blink();
}
}
if (keycount == 4)
{
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3])
{
lcd.noBlink();
lcd.clear();
lcd.home();
lcd.print("Bomba neaktivna!");
lcd.setCursor(0, 1);
lcd.print("Cestitamo!");
keycount = 0;
digitalWrite(greenled, LOW);
delay(15000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Reset the Bomb");
delay(1000000);
}
else
{
lcd.noBlink();
lcd.clear();
lcd.home();
lcd.print("Pogresan kod!");
trycount++;
if (Hours > 0)
{
Hours = Hours / 2;
}
if (Minutes > 0)
{
Minutes = Minutes / 2;
}
if (Seconds > 0)
{
Seconds = Seconds / 2;
}
if (trycount == 2)
{
interval = interval / 10;
}
if (trycount == 3)
{
Minutes = Minutes - 59;
Hours = Hours - 59;
Seconds = Seconds - 59;
}
delay(1000);
keycount = 0;
}
}
}
}
void timer()
{
Serial.print(Seconds);
Serial.println();
if (Hours <= 0)
{
if ( Minutes < 0 )
{
lcd.noBlink();
lcd.clear();
lcd.home();
lcd.print("Bomba je ");
lcd.setCursor (0, 1);
lcd.print("Explodirala!");
while (Minutes < 0)
{
digitalWrite(redled, LOW);
tone(10, 7000, 100);
delay(100);
digitalWrite(redled, HIGH);
tone(10, 7000, 100);
delay(100);
digitalWrite(yellowled, LOW);
tone(10, 7000, 100);
delay(100);
digitalWrite(yellowled, HIGH);
tone(10, 7000, 100);
delay(100);
digitalWrite(greenled, LOW);
tone(10, 7000, 100);
delay(100);
digitalWrite(greenled, HIGH);
tone(10, 7000, 100);
delay(100);
}
}
}
lcd.setCursor (0, 1);
lcd.print ("Timer:");
if (Hours >= 10)
{
lcd.setCursor (7, 1);
lcd.print (Hours);
}
if (Hours < 10)
{
lcd.setCursor (7, 1);
lcd.write ("0");
lcd.setCursor (8, 1);
lcd.print (Hours);
}
lcd.print (":");
if (Minutes >= 10)
{
lcd.setCursor (10, 1);
lcd.print (Minutes);
}
if (Minutes < 10)
{
lcd.setCursor (10, 1);
lcd.write ("0");
lcd.setCursor (11, 1);
lcd.print (Minutes);
}
lcd.print (":");
if (Seconds >= 10)
{
lcd.setCursor (13, 1);
lcd.print (Seconds);
}
if (Seconds < 10)
{
lcd.setCursor (13, 1);
lcd.write ("0");
lcd.setCursor (14, 1);
lcd.print (Seconds);
}
if (Hours < 0)
{
Hours = 0;
}
if (Minutes < 0)
{
Hours --;
Minutes = 59;
}
if (Seconds < 1)
{
Minutes --;
Seconds = 59;
}
if (Seconds > 0)
{
unsigned long currentMillis = millis();
if (currentMillis - secMillis > interval)
{
tone(10, 7000, 50);
secMillis = currentMillis;
Seconds --;
digitalWrite(yellowled, LOW);
delay(10);
digitalWrite(yellowled, HIGH);
delay(10);
}
}
}