from machine import Pin, SPI
import tm1637
from machine import Pin, Timer
from utime import sleep
# import ili9341
# SPI Configuration
spi = SPI(1, baudrate=10000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
display = tm1637.TM1637(clk=Pin(16), dio=Pin(17))
#Initialize the onboard LED as ouput
led = Pin(25, Pin.OUT)
#Initialize timer_one. Used for toggeling the LED
timer_one = Timer()
#Initialize timer_two. Used for updating the time
timer_two = Timer()
mm = 15
ss = 45
change = 0
# Blink LED
def BlinkLED(timer_one):
led.toggle()
# Update Time
def UpdateTime(timer_two):
global mm
global ss
global change
if change == 1:
change = 0
ss = ss + 1
if ss == 60:
ss = 0
mm = mm + 1
if mm == 60:
mm = 0
display.numbers(mm,ss,1)
else:
change = 1
display.numbers(mm,ss,0)
#Initialize count variable with 9950 as initial value
count=9950
# Welcome screen. Scrolling Display.
# Show scrolling text
display.scroll("RPi Pico - TM1637 Display", delay=200)
sleep(2)
# Hi counter
display.show(" ")
display.show("Hi")
sleep(1)
# Execute the Up count loop for 100 times with 0.1 seconds interval
for i in range(101):
# Write the count into display buffer
display.number(count)
# Increment the count
count = count + 1
# Validate the count value. If exceeds 10000, reset it it zero.
if count == 10000:
count = 0
# Sleep for about 100mS.
sleep(0.1)
sleep(1)
# Low Counter
display.show(" ")
display.show("LOW")
sleep(1)
# Execute the Down count loop for 100 times with 0.1 seconds interval
for i in range(101):
# Write the count into display buffer
display.number(count)
# Decrement the count
count = count - 1
# Validate the count value. It its negative value, reset it it 9999.
if count == -1:
count = 9999
# Sleep for about 100mS.
sleep(0.1)
# Demonstrate 3 digit negative number
sleep(2)
# Displaying negative number
display.show(" ")
display.show("NEG")
sleep(2)
#show negative numbers
display.number(-123)
sleep(2)
# Demonstrate 2 digit temperature. Suffix C
display.show(" ")
display.show("Temp")
sleep(2)
#show temperature
display.temperature(99)
sleep(2)
# Demonstrate Time / Clock. Minutes and Seconds are updated.
# 500mS interval toggles the center LEDs.
display.show(" ")
display.show("Time")
sleep(2)
# Initialize the timer one for first time
timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)
# Update time / clock.
timer_two.init(freq=1, mode=Timer.PERIODIC, callback=UpdateTime)
# Initialize display
# display =
display = ili9341.ILI9341(spi, cs=Pin(0), dc=Pin(5), rst=Pin(4))
# Display text
display.fill(ili9341.color565(255, 255, 255)) # Fill screen with white color
display.text("Hello, Wokwi!", 20, 50, ili9341.color565(0, 0, 0))