// Bomb Game Mega.
// include the library code:
#include <LiquidCrystal.h>
#include <Servo.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo myservoa;
//Inputs:
int redwire = 52;
int bluewire = 50;
int greenwire = 48;
//Outputs:
int redone = 53;
int greenone = 51;
int redtwo = 49;
int greentwo = 47;
int redthree = 45;
int greenthree = 43;
int relay = 8;
//Others:
int time = 30;
int redcut = 0;
int bluecut = 0;
int greencut = 0;
int two = 0;
int three = 0;
int militime = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
myservoa.attach(7);
pinMode(redwire, INPUT);
pinMode(bluewire, INPUT);
pinMode(greenwire, INPUT);
pinMode(relay, OUTPUT);
pinMode(redone, OUTPUT);
pinMode(greenone, OUTPUT);
pinMode(redtwo, OUTPUT);
pinMode(greentwo, OUTPUT);
pinMode(redthree, OUTPUT);
pinMode(greenthree, OUTPUT);
digitalWrite(redwire, HIGH);
digitalWrite(bluewire, HIGH);
digitalWrite(greenwire, HIGH);
delay(100);
myservoa.write(50);
digitalWrite(relay, HIGH);
delay(100);
lcd.print(".....ARMING.....");
delay(2000);
digitalWrite(redone, HIGH);
digitalWrite(redtwo, HIGH);
digitalWrite(redthree, HIGH);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(".....ARMED!.....");
}
void loop()
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(time);
// Wirecuts:
if (digitalRead(redwire) == HIGH && redcut == 0)
{
redcut = 1;
delay(100);
}
if (digitalRead(bluewire) == HIGH && bluecut == 0)
{
bluecut = 1;
delay(100);
}
if (digitalRead(greenwire) == HIGH && greencut == 0)
{
greencut = 1;
delay(100);
}
//****************************************************
// Wire cut order: ( red => blue => green )
if (redcut == 1 && bluecut == 0 && greencut == 0 && two == 0)
{
two = 1;
digitalWrite(redone, LOW);
digitalWrite(greenone, HIGH);
Serial.println("Red cut");
}
if (redcut == 1 && bluecut == 1 && greencut == 0 && three == 0)
{
three = 1;
digitalWrite(redtwo, LOW);
digitalWrite(greentwo, HIGH);
Serial.println("Red and Blue cut");
}
if (redcut == 1 && bluecut == 1 && greencut == 1 && three == 1)
{
digitalWrite(redthree, LOW);
digitalWrite(greenthree, HIGH);
Serial.println("Disarmed");
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("....DISARMED.....");
disarmed:
delay(5000);
goto disarmed;
}
//******************************************************
//Wrong
if (bluecut == 1 && two == 0)
{
Serial.println("***** BOOM ! *****");
BOOM();
}
if (greencut == 1 && two == 0)
{
Serial.println("***** BOOM ! *****");
BOOM();
}
if (two == 1 && bluecut == 0 && greencut == 1)
{
Serial.println("***** BOOM ! *****");
BOOM();
}
// Time:
if (time > 0){
militime++;
delay(100);
}
if (militime == 10){
militime = 0;
delay(50);
time--;
}
if (time == 0){
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("0");
BOOM();
}
}
void BOOM()
{
myservoa.write(160);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(".....BOOM!......");
digitalWrite(greenone, LOW);
digitalWrite(greentwo, LOW);
digitalWrite(greenthree, LOW);
boem:
digitalWrite(redone, HIGH);
digitalWrite(redtwo, HIGH);
digitalWrite(redthree, HIGH);
delay(500);
digitalWrite(redone, LOW);
digitalWrite(redtwo, LOW);
digitalWrite(redthree, LOW);
delay(500);
goto boem;
Serial.println("***** BOOM ! *****");
}