#include <Keypad.h>//przywołujemy biblioteke keypad.h
#include <LiquidCrystal_I2C.h>
#define pound 14
#include <Adafruit_NeoPixel.h>
int PIN_LED=46; //Pin donde está conectada la tira de leds
int NUM_LEDS=10; //Número de leds conectados
Adafruit_NeoPixel tiraled = Adafruit_NeoPixel(NUM_LEDS, PIN_LED, NEO_GRB + NEO_KHZ800);
int delayval = 300; // Tiempo de espera
byte puste[8] = {//Tworzymy symbol ukazywany pod "ladowaniem"
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
int Scount = 0; // wartość sekund
int Mcount = 5; // wartość minut
int Hcount = 0; // wartość godzin
int DefuseTimer = 0; // ustawienie czasu na 0
long secMillis = 0; // store last time for second add
long interval = 1000; // interval for seconds
char password[8]; // długość hasła
int currentLength = 0; //defines which number we are currently writing
int i = 0;
char entered[8];
int ledPin = 53; //czerwona ledka
int ledPin2 = 51; //żółta ledka
int ledPin3 = 49; //zielona ledka
int explozja = 47;//tu podłącz przekaźnik
int wire1 = 2;//przewód 1
int wire2 = 3;//przewód 2
int wire3 = 4;//przewód 3
int wire4 = 5;//przewód 4
int wire5 = 6;//przewód 5
int wire6 = 7;//przewód 6
int wire1State = 0;// stan przewodu1
int wire2State = 0;// stan przewodu2
int wire3State = 0;// stan przewodu3
int wire4State = 0;// stan przewodu4
int wire5State = 0;// stan przewodu5
int wire6State = 0;// stan przewodu6
//LiquidCrystal lcd(A14, A13, A12, A11, A10, A9);//piny do których podłączone jest LCD
/* Keypad setup */
const byte ROWS = 4; //4 wiersze
const byte COLS = 4; //4 kolumny
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A7, A6, A5, A4};
byte colPins[COLS] = {A3, A2, A1, A0};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//Keypad keypad = Keypad(makeKeymap(keymap), rowPins, colPins, ROWS, COLS); // Instanciando o keypad
LiquidCrystal_I2C lcd(0x27, 20, 4); // Define o endereço do LCD para 0x27 para um display de 20 colunas e 4 linhas
////////////////////////////////////////////////////////////
void setup(){
lcd.init(); // instrucciones para mensajes LCD
lcd.begin(20,4); // instrucciones para menggunakan lcd 20x4
lcd.backlight(); //instrucciones para encender la lámpara LCD posterior
tiraled.begin(); // Inicialización
tiraled.show(); // Inicialitza tots els pixels apagats
////////////////////////////////////////////////////////////
lcd.createChar(0, puste);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(ledPin2, OUTPUT); // sets the digital pin as output
pinMode(ledPin3, OUTPUT); // sets the digital pin as output
pinMode(wire1, INPUT);
pinMode(wire2, INPUT);
pinMode(wire3, INPUT);
pinMode(wire4, INPUT);
pinMode(wire5, INPUT);
pinMode(wire6, INPUT);
pinMode (explozja, OUTPUT);
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Phantom V.1");
lcd.setCursor(0,1);
lcd.print("By dzidek333");
delay(5000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Ladowanie");
lcd.setCursor(0,1);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
delay(500);
lcd.write(8);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wprowadz czas:");
lcd.setCursor(0,1);
ustawienie();
}
void loop()
{
//arcoiris(20);//Ciclo de arcoiris progresivo en cada pixel
//delay(delayval);
//tcolores(150);//Todos los leds van pasando progresivamente por todos los colores
//delay(delayval);
//rapidamente(300);//Todos los leds se apagan y encienden rápidamente
//delay(delayval);
//alternativamente(tiraled.Color(198,89,48), 100);//Los leds se encienden y apagan alternativamente uno si y uno no
//delay(delayval);
//consecutivamente(tiraled.Color(0, 0, 36), 500); //Los Leds se encienden consecutivamente desdel 0 hasta el último
//delay(delayval);
//colorFull(tiraled.Color(250,0,0));
//delay(delayval);
char key1 = keypad.getKey(); // get the key
{
if (key1 == '1')
{
tone(52, 880, 90);
Mcount ++;
ustawienie();
}
if (Mcount > 58){
tone(52, 880, 90);
Mcount = 0;
Hcount ++;
}
/////////////////////////////////////////
if (key1 == '7')
{
tone(52, 880, 90);
Mcount--;
ustawienie();
}
if (Mcount < 0){
tone(52, 880, 90);
Hcount --;
Mcount = 58;
}
/////////////////////////////////////////
if (key1 == '3')
{
tone(52, 880, 90);
Scount ++;
ustawienie();
}
if (Scount > 58){
tone(52, 880, 90);
Mcount ++;
Scount = 0;
}
/////////////////////////////////////////
if (key1 == '9')
{
tone(52, 880, 90);
Scount--;
ustawienie();
}
if (Scount < 0){
tone(52, 880, 90);
Mcount --;
Scount = 58;
}
/////////////////////////////////////////
}
if (key1=='*')
{
tone(52, 880, 90);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ingrese codigo:");
while (currentLength < 8)
{
lcd.setCursor(currentLength + 4, 1);
lcd.cursor();
char key = keypad.getKey();
key == NO_KEY;
if (key != NO_KEY)
{
tone(52, 880, 90);
if ((key != '*')&&(key != '#'))
{
lcd.print(key);
password[currentLength] = key;
currentLength++;
}
}
}
if (currentLength == 8)
{
delay(1000);
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("ingresado: ");
lcd.setCursor(4,1);
tone(52, 880, 200);
delay(300);
tone(52, 660, 200);
lcd.print(password[0]);
lcd.print(password[1]);
lcd.print(password[2]);
lcd.print(password[3]);
lcd.print(password[4]);
lcd.print(password[5]);
lcd.print(password[6]);
lcd.print(password[7]);
tone(1319, 200);
delay(3000);
lcd.clear();
currentLength = 0;
lcd.print("Kliknij '5'");
lcd.clear();
}
while ( key1!=NO_KEY){
timer();
wire1State = digitalRead(wire1);
wire2State = digitalRead(wire2);
wire3State = digitalRead(wire3);
wire4State = digitalRead(wire4);
wire5State = digitalRead(wire5);
wire6State = digitalRead(wire6);
if (wire1State == HIGH || wire3State == HIGH && wire5State == HIGH){
//Después de sacar el cable 1 O el cable 3 O el cable 5, la bomba explotará
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("exploto!");
digitalWrite(ledPin, HIGH);
if (Hcount > 0)
{ Hcount = Hcount - 1; }
if (Mcount > 0)
{ Mcount = Mcount - 59; }
if (Scount > 0)
{ Scount = Scount - 59; }
delay(1500);
currentLength = 0;
}
if (wire2State == HIGH && wire4State == HIGH && wire6State == HIGH){
//po wyciagnieciu kabelka2 I kabelka4 I kabelka6 bomba jest rozbrojona
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Bomba");
currentLength = 0;
lcd.setCursor(0,1);
lcd.print("verde ");
digitalWrite(ledPin3, HIGH);
delay(1000000000000000000000);
}
char key2 = keypad.getKey();
if (key2 == '*')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Kod: ");
while (currentLength < 8)
{
timer();
char key2 = keypad.getKey();
if (key2 == '#')
{
currentLength = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Kod: ");
timer();
}
else
if (key2 != NO_KEY)
{
tone(52, 880, 200);
lcd.setCursor(currentLength + 7, 0);
lcd.cursor();
lcd.print(key2);
entered[currentLength] = key2;
currentLength++;
tone(1047, 200);
delay(100);
lcd.noCursor();
lcd.setCursor(currentLength + 6, 0);
lcd.print("*");
lcd.setCursor(currentLength + 7, 0);
lcd.cursor();
}
}
if (currentLength == 8)
{
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3] &&entered[4] == password[4] && entered[5] == password[5] && entered[6] == password[6] && entered[7] == password[7])
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Bomba");
currentLength = 0;
lcd.setCursor(0,1);
lcd.print("Rozbrojona");
digitalWrite(ledPin3, HIGH);
delay(1000000000000000000000);
}
else
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("Zle Haslo!");
digitalWrite(ledPin, HIGH);
if (Hcount > 0)
{
Hcount = Hcount - 1;
}
if (Mcount > 0)
{
Mcount = Mcount - 59;
}
if (Scount > 0)
{
Scount = Scount - 59;
}
delay(1500);
currentLength = 0;
}
}
}
} ///////////////////
}
}
//TIRA LED
//Ciclo de arcoiris progresivo en cada pixel
void arcoiris(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< tiraled.numPixels(); i++) {
tiraled.setPixelColor(i, Wheel(((i * 256 / tiraled.numPixels()) + j) & 255));
}
tiraled.show();
delay(wait);
}
}
//Ciclo de arcoiris progresivo en cada pixel
//Todos los leds van pasando progresivamente por todos los colores
void tcolores(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<tiraled.numPixels(); i++) {
tiraled.setPixelColor(i, Wheel((i+j) & 255));
}
tiraled.show();
delay(wait);
}
}
//Todos los leds van pasando progresivamente por todos los colores
//Todos los leds se apagan y encienden rápidamente
void rapidamente(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < tiraled.numPixels(); i=i+3) {
tiraled.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
tiraled.show();
delay(wait);
for (int i=0; i < tiraled.numPixels(); i=i+3) {
tiraled.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Todos los leds se apagan y encienden rápidamente
//Los leds se encienden y apagan alternativamente uno si y uno no
void alternativamente(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < tiraled.numPixels(); i=i+3) {
tiraled.setPixelColor(i+q, c); //turn every third pixel on
}
tiraled.show();
delay(wait);
for (int i=0; i < tiraled.numPixels(); i=i+3) {
tiraled.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Los leds se encienden y apagan alternativamente uno si y uno no
//Los Leds se encienden consecutivamente desdel 0 hasta el último
void consecutivamente(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<tiraled.numPixels(); i++) {
tiraled.setPixelColor(i, c);
tiraled.show();
delay(wait);
}
}
//Los Leds se encienden consecutivamente desdel 0 hasta el último
void colorFull(uint32_t color){
//for (int i = 0; i < tiraled.numPixels(); i++) {
// tiraled.setPixelColor(i, color);
// }
// tiraled.show();
//for(int i=0;i<NUMPIXELS;i++){
for (int i = 0; i < tiraled.numPixels(); i++) {
//Encender led
tiraled.setPixelColor(i, 100,0,0); // Brillo moderado de color rojo
tiraled.show(); // Envia la orden al hardware
delay(delayval);
//Apagar led
tiraled.setPixelColor(i, tiraled.Color(0,0,0)); // Apagar
tiraled.show(); // Envia la orden al hardware
delay(delayval);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return tiraled.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return tiraled.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return tiraled.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
//TIRA LED
////////////////////////////////////////////
void updateScount(){
//display hours - needs fixing for am pm
if(Scount> 59){
//reset to 1
Scount = 1;
}
if(Scount< 10){
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(6,0);
}
else{
lcd.setCursor(5,0);
}
lcd.print(Scount);
}
void ustawienie(){
lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print ("Timer:");
if (Hcount >= 10)
{
lcd.setCursor (8,1);
lcd.print (Hcount);
}
if (Hcount < 10)
{
lcd.setCursor (8,1);
lcd.write ("0");
lcd.setCursor (9,1);
lcd.print (Hcount);
}
lcd.print (":");
if (Mcount >= 10)
{
lcd.setCursor (11,1);
lcd.print (Mcount);
}
if (Mcount < 10)
{
lcd.setCursor (11,1);
lcd.write ("0");
lcd.setCursor (12,1);
lcd.print (Mcount);
}
lcd.print (":");
if (Scount >= 10)
{
lcd.setCursor (14,1);
lcd.print (Scount);
}
if (Scount < 10)
{
lcd.setCursor (14,1);
lcd.write ("0");
lcd.setCursor (15,1);
lcd.print (Scount);
}
}
////////////////////////////////////////////////////////
void timer()
{
if (Hcount <= 0)
{
if ( Mcount < 0 )
{
lcd.noCursor();
tone(52, 880, 4000);
lcd.clear();
lcd.home();
lcd.print("Bomba");
lcd.setCursor (0,1);
lcd.print("Explodowala!");
digitalWrite(explozja, HIGH);
while (Mcount < 0)
{
digitalWrite(ledPin, HIGH); // sets the LED on
tone(110, 90);
delay(100);
digitalWrite(ledPin, LOW); // sets the LED off
tone(110, 90);
delay(100);
digitalWrite(ledPin2, HIGH); // sets the LED on
tone(110, 90);
delay(100);
digitalWrite(ledPin2, LOW); // sets the LED off
tone(110, 90);
delay(100);
digitalWrite(ledPin3, HIGH); // sets the LED on
tone(110, 90);
delay(100);
digitalWrite(ledPin3, LOW); // sets the LED off
tone(110, 90);
delay(100);
}
}
}
lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print ("Timer:");
if (Hcount >= 10)
{
lcd.setCursor (7,1);
lcd.print (Hcount);
}
if (Hcount < 10)
{
lcd.setCursor (7,1);
lcd.write ("0");
lcd.setCursor (8,1);
lcd.print (Hcount);
}
lcd.print (":");
if (Mcount >= 10)
{
lcd.setCursor (10,1);
lcd.print (Mcount);
}
if (Mcount < 10)
{
lcd.setCursor (10,1);
lcd.write ("0");
lcd.setCursor (11,1);
lcd.print (Mcount);
}
lcd.print (":");
if (Scount >= 10)
{
lcd.setCursor (13,1);
lcd.print (Scount);
}
if (Scount < 10)
{
lcd.setCursor (13,1);
lcd.write ("0");
lcd.setCursor (14,1);
lcd.print (Scount);
}
if (Hcount <0)
{
Hcount = 0;
}
if (Mcount <0)
{
Hcount --;
Mcount = 59;
}
if (Scount <1) // if 60 do this operation
{
Mcount --; // add 1 to Mcount
Scount = 59; // reset Scount
}
if (Scount > 0) // do this oper. 59 times
{
unsigned long currentMillis = millis();
if(currentMillis - secMillis > interval)
{
tone(52, 880, 200);
secMillis = currentMillis;
Scount --; // add 1 to Scount
digitalWrite(ledPin2, HIGH); // sets the LED on
delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED off
delay(10); // waits for a second
//lcd.clear();
}
}
}