/**
Arduino Calculator
Copyright (C) 2020, Uri Shaked.
Released under the MIT License.
*/
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
LiquidCrystal_I2C lcd1(0x27, 20, 4);
LiquidCrystal_I2C lcd2(0x26, 20, 4);
RTC_DS1307 rtc;
volatile int coinReceived = 0;
volatile int verification = 0;
bool tv1Ready = true;
bool tv2Ready = true;
bool tv3Ready = true;
bool tv4Ready = true;
bool tv5Ready = true;
bool tv6Ready = true;
bool tv7Ready = true;
bool tv8Ready = true;
int tanggal, bulan, tahun, jam, menit, detik;
/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 1, 0};
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup() {
attachInterrupt(0,incomingImpuls, FALLING);
for (int i = 6; i<=13; i++) {
pinMode(i, OUTPUT);
}
for (int i = 6; i<=13; i++) {
digitalWrite(i, LOW);
}
lcd1.init();
lcd1.backlight();
while (! rtc.begin()) {
lcd1.setCursor(0, 1);
lcd1.print("RTC Tidak Ditemukan");
}
lcd1.setCursor(0, 0);
lcd1.print("Selamat datang");
lcd1.setCursor(0, 1);
lcd1.print("Silakan masukkan ");
delay(500);
lcd1.clear();
}
void getTime() {
DateTime now = rtc.now(); //Data hari
tanggal = now.day(); //Data tanggal
bulan = now.month(); //Data bulan
tahun = now.year(); //Data tahun
jam = now.hour(); //Data jam
menit = now.minute(); //Data menit
detik = now.second();
}
void incomingImpuls() {
coinReceived++;
verification = 1;
}
void menuInsertDuration() {
}
void loop() {
getTime();
mainMenu();
if (verification == 1) {
menuInsertDuration();
}
char key = keypad.getKey();
if (key) {
lcd1.setCursor(19, 3);
lcd1.print(key);
}
delay(500);
}
void mainMenu() {
//lcd1.clear();
lcd1.setCursor(1,0);
lcd1.print("-TIMER-");
lcd1.setCursor(12,0);
lcd1.print("-TIMER-");
lcd1.setCursor(0,1);
lcd1.print("TV1:");
lcd1.setCursor(11,1);
lcd1.print("TV2:");
lcd1.setCursor(1,0);
lcd1.print("-TIMER-");
lcd1.setCursor(12,0);
lcd1.print("-TIMER-");
lcd1.setCursor(0,1);
lcd1.print("TV1:");
lcd1.setCursor(11,1);
lcd1.print("TV2:");
}