Kód: Vybrať všetko
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F // Define I2C Address where the PCF8574A is
// Address can be changed by soldering A0, A1, or A2
// Default is 0x27
// map the pin configuration of LCD backpack for the LiquidCristal class
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,
En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,
BACKLIGHT_PIN, POSITIVE);
const int spustacresettlacidlo = 12; //The pin for spustacresettlacidlo
long lastPressedspustacresettlacidlo = 0; //Last millisecond we pressed spustacresettlacidlo
boolean run = false; //Should the system run?
int spustacresettlacidloState = LOW; //The value the spustacresettlacidlo reads
int spustacresettlacidloCurrState = LOW; //The last value of spustacresettlacidlo
long timer = 0; //The timer
int second = 0;
int minute = 0;
int tenth = 0;
void setup() {
lcd.begin(20, 4); // intialise the LCD.
lcd.setBacklight(HIGH); // Turn on backlight, LOW for off
pinMode(spustacresettlacidlo, INPUT);
lcd.setCursor(0,0);
lcd.print("00:00:0 L");
lcd.setCursor(0,1);
lcd.print("00:00:0 P");
}
void tickClock() {
Serial.println(millis() /10);
if((timer - millis()/100) >= 100 || timer == 0) {
tick();
timer = millis()/100;
}
}
void loop() {
tickClock(); //Start ticking the clock
spustacresettlacidloState = digitalRead(spustacresettlacidlo);
checkStart();
}
void checkStart() {
if(spustacresettlacidloState != spustacresettlacidloCurrState) { //Check if the button state has changed
if(spustacresettlacidloState == HIGH && (millis()-lastPressedspustacresettlacidlo) > 100 || lastPressedspustacresettlacidlo == 0) {
lastPressedspustacresettlacidlo = millis();
run = !run; //Switch the running state
}
}
spustacresettlacidloCurrState = spustacresettlacidloState; //Set the current state equals the button state
}
void tick() {
if(run) {
updateLCD();
if(tenth == 9) {
tenth = 0;
if(second == 59) {
second = 0;
minute++;
} else {
second++;
}
} else {
tenth++;
}
}
}
void updateLCD() {
//
lcd.setCursor(0,0);
if(minute < 10) { // If hour does not have 2 digits
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if(second < 10) { // If minute does not have 2 digits
lcd.print("0");
}
lcd.print(second, DEC);
lcd.print(":");
lcd.print(tenth, DEC);
//
lcd.setCursor(0,1);
if(minute < 10) { // If hour does not have 2 digits
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if(second < 10) { // If minute does not have 2 digits
lcd.print("0");
}
lcd.print(second, DEC);
lcd.print(":");
lcd.print(tenth, DEC);
}