"""
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Raspberry Pi Pico 7-Segment Display Counter (MicroPython)┃
┃ ┃
┃ A program to demonstrate the use of a 7-segment display ┃
┃ by implementing an ascending/descending hexadecimal ┃
┃ counter based on the state of an input switch. ┃
┃ ┃
┃ Copyright (c) 2023 Anderson Costa ┃
┃ GitHub: github.com/arcostasi ┃
┃ License: MIT ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
"""
from machine import Pin
from utime import sleep
from machine import I2C, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = i2c.scan()[0]
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
pins = [
Pin(2, Pin.OUT), # A
Pin(3, Pin.OUT), # B
Pin(4, Pin.OUT), # C
Pin(5, Pin.OUT), # D
Pin(6, Pin.OUT), # E
Pin(8, Pin.OUT), # F
Pin(7, Pin.OUT), # G
]
# Common anode 7-segment display digit patterns
MISSISSIPPI = [
[0, 1, 0, 1, 0, 1, 0], # M
[0, 1, 1, 1, 0, 1, 1], # I
[0, 1, 0, 0, 1, 0, 1], # S
[0, 1, 0, 0, 1, 0, 1], # S
[0, 1, 1, 1, 0, 1, 1], # I
[0, 1, 0, 0, 1, 0, 1], # S
[0, 1, 0, 0, 1, 0, 1], # S
[0, 1, 1, 1, 0, 1, 1], # I
[0, 0, 1, 1, 0, 0, 0], # P
[0, 0, 1, 1, 0, 0, 0], # P
[0, 1, 1, 1, 0, 1, 1], # I
]
ilovedsp = [
[0, 1, 1, 1, 0, 1, 1, 1], # i
[1, 1, 1, 0, 0, 0, 1, 1], # l
[1, 1, 0, 0, 0, 1, 0, 1], # o
[1, 0, 1, 0, 1, 0, 1, 1], # v
[0, 1, 1, 0, 0, 0, 0, 1], # e
[1, 0, 0, 0, 0, 1, 0, 1], # d
[0, 1, 0, 0, 1, 0, 1, 1], # s
[0, 0, 1, 1, 0, 0, 0, 1], # p
]
while True:
#MISSISSIPPI
lcd.putstr("MISSISSIPPI")
for i in range(len(MISSISSIPPI)):
for j in range(len(pins)):
pins[j].value(MISSISSIPPI[i][j])
sleep(0.5)
lcd.clear()
# ILOVEDSP
lcd.putstr("ILOVEDSP")
for i in range(len(ilovedsp)):
for j in range(len(pins)):
pins[j].value(ilovedsp[i][j])
sleep(0.5)
lcd.clear()