# Esp32 - counter for 4 digit 7-segment Led's
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-06-06  initial release

from	machine	import	Pin, I2C
import	time

# ====================== 4 digit LCD driver =============================

i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)

dig0 = b'\x3F'
dig1 = b'\x06'
dig2 = b'\x5B'
dig3 = b'\x4F'
dig4 = b'\x66'
dig5 = b'\x6D'
dig6 = b'\x7D'
dig7 = b'\x07'
dig8 = b'\x7F'
dig9 = b'\x6F'

# ============================ Main =======================================

# Show decimal and hexadecimal on 4 digit 7-segm LCD
def main():
    i2c.writeto(36, b'\x31')
    while True:
        i2c.writeto(55, dig0); time.sleep(1)
        i2c.writeto(55, dig1); time.sleep(1)
        i2c.writeto(55, dig2); time.sleep(1)
        i2c.writeto(55, dig3); time.sleep(1)
        i2c.writeto(55, dig4); time.sleep(1)
        i2c.writeto(55, dig5); time.sleep(1)
        i2c.writeto(55, dig6); time.sleep(1)
        i2c.writeto(55, dig7); time.sleep(1)
        i2c.writeto(55, dig8); time.sleep(1)
        i2c.writeto(55, dig9); time.sleep(1)
    

main()

# ===================== End =========================
