from machine import Pin, SPI, I2C
import utime
import ds1307
from ili9341 import ILI9341, color565
import glcdfont
import tt14
import tt24
import tt32
# ILI9341 configuration
spi = SPI(1, baudrate=40000000, sck=Pin(10), mosi=Pin(11), miso=Pin(12))
display = ILI9341(spi, cs=Pin(15), dc=Pin(13), rst=Pin(14), w=240, h=320, r=0)
# DS1307 configuration
i2c = I2C(1, scl=Pin(27), sda=Pin(26), freq=100000)
rtc = ds1307.DS1307(i2c)
def display_time(display, rtc):
previous_time = None
display.set_font(tt32)
display.set_color(color565(255, 255, 255), color565(0, 0, 0)) # Set text color to white, background to black
display.set_pos(40, 120)
display.print('Current Time:')
while True:
# Get the current time from the RTC
current_time = rtc.datetime()
formatted_time = "{:02}:{:02}:{:02}".format(current_time[4], current_time[5], current_time[6])
if formatted_time != previous_time:
# Clear the specific area by drawing a filled rectangle
display.fill_rectangle(10, 40, 220, 32, color565(0, 0, 0)) # Adjusted height to match font size
# Display the updated time
display.set_pos(80, 160)
display.print(formatted_time)
print(f"Current time: {formatted_time}")
previous_time = formatted_time
utime.sleep(1)
def main():
print("Starting the display and RTC test")
display_time(display, rtc)
if __name__ == '__main__':
main()