Chcę zrobić zegarek wyświetlany na wyświetlaczu za pomocą modułu DS1302 ale biblioteka do tego modułu gdy sekundy lub minuty lub godziny wynosi od 1 do 9 to jest to jedna cyfra a ja chce zrobić żeby gdy będzie np. sekundy od 1 do 9 to przed ta cyfra będzie jeszcze zero żeby to były 2 cyfry a nie jedna i zrobiłem to za pomocą if ale nie działa. Poniżej jest ten skrypt. Wie ktoś dlaczego nie działa albo jak to zrobić inaczej?
#include <LiquidCrystal_I2C.h>
#include <stdio.h>
#include <DS1302.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,16, 2);
namespace {
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
rtc.writeProtect(false);
rtc.halt(false);
// Sunday, September 22, 2013 at 01:38:50.
Time t(2019, 12, 26, 23, 59, 00, Time::kSunday);
// Set the time and date on the chip.
rtc.time(t);
int r;
}
void loop() {
Time t = rtc.time();
if(t.sec>=0 and t.sec<=9 and t.min>9 and t.hr>9);{
lcd.setCursor(0,0);
lcd.print(t.hr);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print("0");
lcd.print(t.sec);
}
if(t.sec>9 and t.min>=0 and t.min<=9 and t.hr>9);{
lcd.setCursor(0,0);
lcd.print(t.hr);
lcd.print(":");
lcd.print("0");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
}
if(t.sec>9 and t.min>9 and t.hr>=0 and t.hr<=9);{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(t.hr);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
}
if(t.sec>=0 and t.sec<=9 and t.min>=0 and t.min<=9 and t.hr>9);{
lcd.setCursor(0,0);
lcd.print(t.hr);
lcd.print(":");
lcd.print("0");
lcd.print(t.min);
lcd.print(":");
lcd.print("0");
lcd.print(t.sec);
}
if(t.sec>=0 and t.sec<=9 and t.min>9 and t.hr>=0 and t.hr<=9);{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(t.hr);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print("0");
lcd.print(t.sec);
}
if(t.sec>9 and t.min>=0 and t.min<=9 and t.hr>=0 and t.hr<=9);{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(t.hr);
lcd.print(":");
lcd.print("0");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
}
if(t.sec>=0 and t.sec<=9 and t.min>=0 and t.min<=9 and t.hr>=0 and t.hr<=9);{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(t.hr);
lcd.print(":");
lcd.print("0");
lcd.print(t.min);
lcd.print(":");
lcd.print("0");
lcd.print(t.sec);
}
if(t.sec>9 and t.min>9 and t.hr>9);{
lcd.setCursor(0,0);
lcd.print(t.hr);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
lcd.print(t.sec);
}
delay(999);
}