Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Time.h>
- #include <TimeLib.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <LiquidCrystal.h> //Dołączenie bilbioteki
- LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); //Informacja o podłączeniu nowego wyświetlacza
- #include<math.h>
- #include "Keypad.h"
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //three columns
- 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 }; //Piny, do których podłączamy wyprowadzenia od rzędów
- byte colPins[COLS] = { 5, 4, 3, 2 }; //Piny, do których kolumn wyprowadzenia od rzędów
- Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
- int wyn_Mno, k = 0, pojemnik1 = 0, pojemnik2 = 0, wpis_int = 0, wx = 0, PIERWSZA_LICZBA = 0, DRUGA_LICZBA = 0, ILOCZYN = 0;
- int x = 0, klucz = 0, buff;
- int a = 0,flash=0;
- bool access = false, boolowskie_gowno = false,blinker,bomb_has_been_planted=false;
- char key;
- char wpis1[4], wpis2[3];
- unsigned char i, j;
- time_t t;
- int minuty = 10;
- int sekundy = 00, delta_sekund = 0, w = 0;
- String tekst;
- void czas(String tekst)
- {
- time_t t = now();
- delta_sekund = (sekundy - second(t));
- if (delta_sekund<0)
- {
- delta_sekund += 59;
- }
- lcd.setCursor(9, 0);
- if ((minute(t) != w) || (delta_sekund == 9)) //POTRZEBNE DO ODSWIERZENIA KODU PO UPLYWIE MINUTY
- {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(tekst);
- w = minute(t);
- lcd.setCursor(9, 0);
- }
- lcd.print(minuty - minute(t));
- lcd.print(":");
- lcd.print(delta_sekund);
- }
- void buzzerOn()
- {
- int out = 10;//DO BUZZERA
- for (int i = 0; i <80; i++)
- { // number of cycles to sound
- digitalWrite(out, HIGH); // turn buzzer ON
- delay(1);// Delay 1ms set frequency 1
- digitalWrite(out, LOW); // turn buzzer OFF
- delay(1);// delay ms
- }
- for (int i = 0; i <100; i++)
- { // number of cycles to sound
- digitalWrite(out, HIGH); // turn buzzer ON
- delay(2);// delay 2ms set frequency 2
- digitalWrite(out, LOW); // turn buzzer OFF
- delay(2);// delay 2ms
- }
- }
- void Bang()
- {
- pinMode(13, OUTPUT);//TO OD GLOSNIKA
- digitalWrite(13, HIGH);//TO OD GOLSNIKA
- }
- void redLED(bool OnOf) //12PIN
- {
- pinMode(12, OUTPUT); //
- if(OnOf==true)
- {
- digitalWrite(12, HIGH);
- }
- else
- {
- digitalWrite(12, LOW);
- }
- }
- void blueLED(bool OnOf)
- {
- pinMode(11, OUTPUT); // NIEBIESKI
- if(OnOf==true)
- {
- digitalWrite(11, HIGH); //NIEBIESKI
- }
- else
- {
- digitalWrite(11, LOW); //NIEBIESKI
- }
- }
- void mruganie(bool kolor,bool blinker)
- {
- if(blinker==true)
- {
- flash++;
- flash = flash % 100;
- if ((flash >= 0) && (flash <= 50))
- {
- if (kolor == true)
- {
- redLED(true);
- }
- else
- {
- blueLED(true);
- }
- }
- else
- {
- if (kolor == true)
- {
- redLED(false);
- }
- else
- {
- blueLED(false);
- }
- }
- }
- }
- void setup()////////////////////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!SETUP
- {
- PIERWSZA_LICZBA = 0;
- Serial.begin(9600);
- a = now();
- pojemnik1 = 0;
- pinMode(10, OUTPUT); //Konfiguracja 10 jako wyjście
- lcd.begin(16, 2); //Deklaracja typu
- lcd.setCursor(0, 0); //Ustawienie kursora
- lcd.blink(); //Włącznie kursora
- lcd.print("PODAJ A"); //Wyświetlenie tekstu
- czas(tekst);
- lcd.setCursor(0, 1); //Ustawienie kursora
- lcd.print("<0;31>");
- time_t t = now();
- delta_sekund = (sekundy - second(t)) % 60;
- }
- void loop()//////////////////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LOOOOOOOOOP
- {
- if (bomb_has_been_planted==false)
- {
- mruganie(true,true);
- }
- else
- {
- redLED(true);
- }
- key = keypad.getKey();
- czas(tekst);
- if ((PIERWSZA_LICZBA == 0) || (DRUGA_LICZBA == 0))
- {
- if (key != NO_KEY)
- {
- //buzzerOn();
- wpis1[k] = key - '0';
- wpis_int = (int)wpis1[k];
- lcd.setCursor(8, 1);
- if (k == 1)
- {
- lcd.setCursor(9, 1);
- }
- lcd.print(wpis_int);
- delay(300);
- x += wpis_int*pow(10, 1 - k);
- Serial.print(x);
- Serial.print("\n");
- k++;
- if (x >= 31)
- {
- x = 31;
- }
- if (k == 2)
- {
- if (PIERWSZA_LICZBA != 0)
- {
- DRUGA_LICZBA = x;
- }
- else
- {
- PIERWSZA_LICZBA = x;//nowa zmienna
- }
- x = 0;
- k = 0;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Podaj B");
- lcd.setCursor(0, 1); //Ustawienie kursora
- lcd.print("<0;31>");
- if ((PIERWSZA_LICZBA != 0) && (DRUGA_LICZBA != 0))
- {
- x = 0;//pewnie zbędne
- k = 0;//pewnie zbędne
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print(PIERWSZA_LICZBA);
- lcd.print("*");
- lcd.print(DRUGA_LICZBA);
- lcd.print("=");
- ILOCZYN = PIERWSZA_LICZBA*DRUGA_LICZBA;
- access = true;
- //lcd.print(ILOCZYN);
- }
- }
- }
- }
- if (access == true)
- {
- if (boolowskie_gowno == true)
- {
- if (key != NO_KEY)
- {
- Serial.print("boolowskie_gowno == true\n");
- wpis1[k] = key - '0';
- wpis_int = (int)wpis1[k];
- x += wpis_int*pow(10, 2 - k);
- lcd.setCursor(7 + k, 1); //Ustawienie kursora
- lcd.print(wpis_int);
- k++;
- Serial.println(x + 1);
- Serial.print(" access\n");
- if (k == 3)
- {
- wyn_Mno = x + 1;
- x = 0;
- k = 0;
- if (wyn_Mno == ILOCZYN)
- {
- delay(250);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Bomb has");
- lcd.setCursor(0, 1);
- lcd.print("been planted.");
- delay(1000);
- access = false;
- bomb_has_been_planted=true;
- }
- else
- {
- Serial.println("ZLE HASLO");
- delay(250);
- lcd.clear();
- lcd.setCursor(0, 1);
- lcd.print(PIERWSZA_LICZBA);
- lcd.print("*");
- lcd.print(DRUGA_LICZBA);
- lcd.print("=");
- }
- }
- //mozliwosc dodania "lcd.print(String tekst);"
- }
- }
- else
- {
- boolowskie_gowno = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement