#include <Arduino.h>
// Define pins used for wires and LEDs.
// C1 - Core number | CW - Marking the correct wire | WW - Marking the wrong wire.
const int C1CW = 13;
const int C1WW = 12;
const int C1Led = 2;
const int C2CW = 11;
const int C2WW = 10;
const int C2Led = 3;
const int C3CW = 9;
const int C3WW = 8;
const int C3Led = 4;
const int C4CW = 7;
const int C4WW = 6;
const int C4Led = 5;
// Define pins for activation switch and buzzer.
const int buzzer = A1;
const int activator = A0;
// Define initial countdown time.
const int initialTime = 240;
// Define speedup for cutting the wrong wire.
const float speedupFactor = 1.5;
// Initialize countdown time and wire states.
int countdownTime = initialTime;
int C1CWState = 0;
int C1WWState = 0;
int C2CWState = 0;
int C2WWState = 0;
int C3CWState = 0;
int C3WWState = 0;
int C4CWState = 0;
int C4WWState = 0;
void setup()
{ // put your setup code here, to run once:
// Set wire pins as input and LED pins as output.
pinMode(C1CW, INPUT);
pinMode(C1WW, INPUT);
pinMode(C1Led, OUTPUT);
pinMode(C2CW, INPUT);
pinMode(C2WW, INPUT);
pinMode(C2Led, OUTPUT);
pinMode(C3CW, INPUT);
pinMode(C3WW, INPUT);
pinMode(C3Led, OUTPUT);
pinMode(C4CW, INPUT);
pinMode(C4WW, INPUT);
pinMode(C4Led, OUTPUT);
// Set initial LED state to off.
digitalWrite(C1Led, LOW);
digitalWrite(C2Led, LOW);
digitalWrite(C3Led, LOW);
digitalWrite(C4Led, LOW);
// Initialize serial communication for debugging.
Serial.begin(9600);
}
void loop()
{ // put your main code here, to run repeatedly:
// delay(10); // Delay a little bit to improve simulation performance
// Read the wire states.
C1CWState = digitalRead(C1CW);
C1WWState = digitalRead(C1WW);
C2CWState = digitalRead(C2CW);
C2WWState = digitalRead(C2WW);
C3CWState = digitalRead(C3CW);
C3WWState = digitalRead(C3WW);
C4CWState = digitalRead(C4CW);
C4WWState = digitalRead(C4WW);
// Check if correct wire was cut.
if (C1CW, C2CW, C3CW, C4CW == HIGH)
{
Serial.println("Ispravna žica prerezana - Prva jezgra deaktivirana!");
digitalWrite(C1Led, HIGH); // Turn on the LED
while (true) // Wait forever
{
/* code */
}
}
// Check if wrong wire was cut.
if (C1WW, C2WW, C3WW, C4WW == HIGH)
{
Serial.println("Kriva žica prerezana - Odbrojavanje ubrzano!");
countdownTime = countdownTime / speedupFactor;
}
// Decrement the countdown timer and check if it's expired.
countdownTime--;
if (countdownTime <=0)
{
Serial.println("Odbrojavanje je isteklo - Bomba je eksplodirala!");
// Turn on the LEDs
digitalWrite(C1Led, HIGH);
digitalWrite(C2Led, HIGH);
digitalWrite(C3Led, HIGH);
digitalWrite(C4Led, HIGH);
while (true) // Wait forever
{
/* code */
}
}
// Delay for 1 second before checking the wire states again.
delay(1000);
}