#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
RTC_DS1307 rtc;
#define SCALE_CLEAR0 0
#define SCALE_CLEAR1 1
#define SCALE_CLEAR2 2
#define SCALE_CLEAR3 3
#define SCALE_CLEAR4 4
#define SCALE_CLEAR5 5
int level;
int sec_num;
int num;
void setup() {
Serial.begin(9600);
// Init
lcd.init();
lcd.backlight();
rtc.begin();
byte scaleChar0[8] = {
0b10101,
0b10101,
0b10100,
0b10000,
0b10000,
0b10000,
0b10000,
0b00000
};
lcd.createChar(SCALE_CLEAR0, scaleChar0);
byte scaleChar1[8] = {
0b11101,
0b11101,
0b01100,
0b01000,
0b01000,
0b01000,
0b01000,
0b00000
};
lcd.createChar(SCALE_CLEAR1, scaleChar1);
byte scaleChar2[8] = {
0b10101,
0b10101,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100,
0b00000
};
lcd.createChar(SCALE_CLEAR2, scaleChar2);
byte scaleChar3[8] = {
0b10111,
0b10111,
0b00110,
0b00010,
0b00010,
0b00010,
0b00010,
0b00000
};
lcd.createChar(SCALE_CLEAR3, scaleChar3);
byte scaleChar4[8] = {
0b10101,
0b10101,
0b00101,
0b00001,
0b00001,
0b00001,
0b00001,
0b00000
};
lcd.createChar(SCALE_CLEAR4, scaleChar4);
byte scaleChar5[8] = {
0b10101,
0b10101,
0b00100,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
lcd.createChar(SCALE_CLEAR5, scaleChar5);
displaybackscale();
displaySCALE();
}
void displaybackscale()
{
lcd.setCursor(0, 0);
for (byte i = 0; i < 12; i ++)
{
lcd.write(SCALE_CLEAR5);
}
}
void loop() {
DateTime now = rtc.now();
sec_num = now.second();
lcd.setCursor(0, 1);
lcd.print(sec_num);
lcd.print(" ");
Serial.println(sec_num, DEC);
delay(1000);
displaybackscale();
displaySCALE();
}
void displaySCALE()
{
int y = sec_num / 5;
lcd.setCursor(y, 0);
level = sec_num;
if (level == 1 || level == 6 || level == 11 || level == 16 )
{
level = 0;
lcd.write(level);
} else {
level += 1;
lcd.write(level);
}
Serial.println(level);
}