#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16, 2);
#define potPin A0
#define SW0 2
#define SW1 3
#define SW2 4
char digit [6] = {1, 2, 3, 4, 5, 6};
int theSec, theMin, theHr;
byte real_00[8] = {B01110, B01010, B01010, B01010, B01010, B01010, B01010, B01010}; // bits for special character 1/8
byte real_01[8] = {B01010, B01010, B01010, B01010, B01010, B01010, B01010, B01110}; // bits for special character 2/8
byte real_02[8] = {B00010, B00010, B00010, B00010, B00010, B00010, B00010, B00010}; // bits for special character 3/8
byte real_03[8] = {B01110, B00010, B00010, B00010, B00010, B00010, B00010, B01110}; // bits for special character 4/8
byte real_04[8] = {B01110, B01000, B01000, B01000, B01000, B01000, B01000, B01110}; // bits for special character 5/8
byte real_05[8] = {B01110, B00010, B00010, B00010, B00010, B00010, B00010, B00010}; // bits for special character 6/8
byte real_06[8] = {B01110, B01010, B01010, B01010, B01010, B01010, B01010, B01110}; // bits for special character 7/8
byte real_07[8] = {B00010, B00010, B00010, B00010, B00010, B00010, B00010, B01110}; // bits for special character 8/8
// special character used for the individual digits, each digit is made from 4 special characters. Character 254 is empty, character 255 is fully filled rectangle
byte real_digits[10][2] = { {0, 1}, {2, 2}, {3, 4}, {3, 3}, {1, 5}, {4, 3}, {4, 6}, {5, 2}, {6, 6}, {6, 3} };
// switch font = set special characters and populate current_font_digits with digits from the selected font
void set_font_real() {
lcd.createChar(0, real_00);
lcd.createChar(1, real_01);
lcd.createChar(2, real_02);
lcd.createChar(3, real_03);
lcd.createChar(4, real_04);
lcd.createChar(5, real_05);
lcd.createChar(6, real_06);
lcd.createChar(7, real_07);
}
void create_digit(byte angka, byte xpos, byte ypos) {
lcd.setCursor(xpos, ypos);
lcd.write(real_digits[angka][0]);
lcd.setCursor(xpos, ypos + 1);
lcd.write(real_digits[angka][1]);
}
void create_titikDua(byte angka, byte xpos, byte ypos) {
lcd.setCursor(xpos, ypos);
lcd.write(165);
lcd.setCursor(xpos, ypos + 1);
lcd.write(165);
}
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight();
pinMode(SW0, INPUT_PULLUP);
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
}
void loop() {
set_font_real();
theSec++;
if (theSec == 60) {
theSec = 0;
theMin++;
if (theMin == 60) {
theMin = 0;
theHr++;
if (theHr == 24) {
theHr = 0;
}
}
}
/*
if (digitalRead(SW0) == 0 && theSec < 1100) {
theSec++;
if (theSec == 60) {
theSec = 0;
theMin++;
if (theMin == 60) {
theMin = 0;
theHr++;
if (theHr == 24) {
theHr = 0;
}
}
}
}
if (digitalRead(SW1) == 0 && theSec > 0) {
theSec--;
}
if (digitalRead(SW2) == 0) {
theSec = 0;
}
*/
digit [0] = (theHr / 10) % 10;
create_digit(digit [0], 8, 0);
digit [1] = (theHr) % 10;
create_digit(digit [1], 9, 0);
create_titikDua(0, 10, 0);
digit [2] = (theMin / 10) % 10;
create_digit(digit [2], 11, 0);
digit [3] = (theMin) % 10;
create_digit(digit [3], 12, 0);
create_titikDua(0, 13, 0);
digit [4] = (theSec / 10) % 10;
create_digit(digit [4], 14, 0);
digit [5] = (theSec) % 10;
create_digit(digit [5], 15, 0);
Serial.println(theSec);
}