//#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //Change the HEX address
const int buttonPin = 11;
const int ledPin = 13;
const int buttonPin2 = 12;
const int ledPin2 = 9;
int Status1 = 0;
int Status2 = 0;
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;
void setup()
{
pinMode(redled, OUTPUT);
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
digitalWrite(redled,HIGH);
digitalWrite(yellowled,HIGH);
digitalWrite(greenled,HIGH);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin2, INPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bomba ARDUBA");
delay(1000);
if (keycount == 11);
{
Hours = (0 * 10) + 0;
Minutes = (0 * 10) + 1;
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 (" ");
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 (" ");
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 (" ");
lcd.setCursor (14, 1);
lcd.print (Seconds);
}
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("spremno");
delay (500);
keycount = 12;
}
while (keycount == 12)
{
Status1 = digitalRead(buttonPin);
if (Status1 == HIGH)
{
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, LOW);
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 aktivirana!");
lcd.setCursor(0, 1);
lcd.print("Countdown start");
delay(3000);
lcd.clear();
keycount = 0;
}
Status2 = digitalRead(buttonPin2);
if (Status2 == HIGH)
{
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
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 aktivirana!");
lcd.setCursor(0, 1);
lcd.print("Countdown start");
delay(3000);
lcd.clear();
keycount = 0;
}
}
}
void loop()
{
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 (" ");
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 (" ");
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 (" ");
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);
}
}
}