Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- const int buttonPin = 7; // the number of the pushbutton pin
- int buttonState = 0; // variable for reading the pushbutton status
- int prevButtonState = 0;
- int milisek = 0; // zmienna typu intiger z wartością początkową 0
- int sek = 0; // zmienna typu intiger z wartością początkową 0
- int minut =0; // zmienna typu intiger z wartością początkową 0
- int startTime = millis();
- bool IsCounting = false;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //definiujemy zmienną lcd, przez którą będziemy się
- //komunikować z modułem; podajemy do których
- //pinów podłączyliśmy się w Arduino
- void setup() // parametry przygotowawcze
- {
- lcd.begin(16,2); // parametry wyświetlacza
- pinMode(buttonPin, INPUT); // not really necessary, pins default to INPUT anyway
- pinMode(10, OUTPUT);
- }
- bool startLicznika()
- {
- buttonState = digitalRead(buttonPin);
- if (buttonState == 1 && prevButtonState == 0)
- {
- prevButtonState = 1;
- return false;
- }
- else if (buttonState == 0 && prevButtonState == 1 && IsCounting == false)
- {
- prevButtonState = 0;
- IsCounting = true;
- milisek = 0; // zmienna typu intiger z wartością początkową 0
- sek = 0; // zmienna typu intiger z wartością początkową 0
- minut =0; // zmienna typu intiger z wartością początkową 0
- startTime = millis();
- return true;
- }
- else if (buttonState == 0 && prevButtonState == 1 && IsCounting == true)
- {
- IsCounting = false;
- prevButtonState = 0;
- return false;
- }
- else if (buttonState == 0 && prevButtonState == 0 && IsCounting == true)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void buzzer()
- {
- if (buttonState == 1)
- {
- digitalWrite(10, HIGH);
- }
- else
- {
- digitalWrite(10, LOW);
- }
- }
- void print() //funkcja updatujaca wyświetlacz
- {
- lcd.setCursor(0,0); // ustawienie kursora
- lcd.print ("t "); // wyświetlenie tekstu
- lcd.print (minut); // wyświetlenie wartości przypisanej do godziny
- lcd.print (":"); // wyświetlenie tekstu -spacja
- lcd.print (sek); // wyświetlenie wartości przypisanej do dni
- lcd.print (":"); // wyświetlenie tekstu -spacja
- lcd.print (milisek); // wyświetlenie tekstu -spacja
- buttonState = digitalRead(buttonPin);
- lcd.setCursor(0,1); // ustawienie kursora
- lcd.print (buttonState);
- lcd.setCursor(3,1); // ustawienie kursora
- lcd.print (prevButtonState);
- lcd.setCursor(6,1); // ustawienie kursora
- lcd.print (IsCounting);
- }
- void loop() // główna pętla
- {
- buzzer();
- print();
- if (startLicznika() == true)
- {
- if (milisek > 999)
- {
- milisek = 0;
- sek ++;
- startTime = millis();
- lcd.clear();
- }
- if (sek > 59)
- {
- sek = 0;
- minut ++;
- }
- milisek = millis() - startTime;
- }
- else
- {
- print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment