TonyGo

CLK2v6

Feb 28th, 2026
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.90 KB | Source Code | 0 0
  1. # CLK2 v6 -  Minute timer added + Time Fix + % up and down (1 and 5)
  2.  
  3. # Change colours via buttons - Press X to start
  4. # Author: Tony Goodhew - 27 Feb 2026 - Tonygo2 on Pimoroni Forum
  5.  
  6. # Requirements: PRESTO with Qw/ST Pad fitted and library installed
  7. # Uses Vector fonts on hour elements
  8.  
  9. # Press Y to set time and A to return and RUN on
  10. # L and R switch between Hours and Minutes
  11. # Press U and D to change value
  12. # RED is active value GREEN is inactive
  13. # 5 Minute positions emphasised
  14. # Uses Epoch time - OK until 2038
  15. # Ajusted to Ben's Roll-over sequence
  16. # Pad + and - turn visible numbers ON and OFF
  17.  
  18. # X to start change colour section
  19. # U and D to cycle through colours
  20. # B to return to running clock
  21. # Will probably need to reset time
  22.  
  23. # While the normal clock is running button B will start the minute timer
  24. # Press U and D to set minutes - 1s
  25. # Press L and R to set minutes in 5 sec jumps
  26. # Press A to start count-down timer
  27. # Press X to abort the timer and return to normal clock running
  28.  
  29. import gc
  30. import time
  31. from machine import I2C, Pin
  32. import math
  33. from qwstpad import QwSTPad
  34. from presto import Presto
  35. from picovector import ANTIALIAS_FAST, PicoVector, Polygon, Transform
  36.  
  37. # Setup for the Presto display
  38. presto = Presto(full_res=True)
  39. display = presto.display
  40. touch = presto.touch # Activate touch
  41. i2c = I2C(id=0,scl=Pin(41), sda=Pin(40)) # PRESTO
  42.  
  43. # Connect single default I2C address QwSTPad
  44. try:
  45.     qwstpad = QwSTPad(i2c, 0x21)
  46. except OSError:
  47.     print("QwSTPad: Not Connected ... Exiting")
  48.     raise SystemExit
  49.  
  50. # Turn of LED on qw/stpad
  51. qwstpad.set_leds(0)
  52.  
  53. WIDTH, HEIGHT = display.get_bounds()
  54. #WIDTH = 200
  55. #HEIGHT = WIDTH
  56. display.set_font("bitmap8") # Change the font
  57.  
  58. # Create some colours - not all used at the moment
  59. RED = display.create_pen(255,0,0)
  60. PINK = display.create_pen(250, 125, 180)
  61. PINK2 = display.create_pen(247,21,157)
  62. ORANGE = display.create_pen(245, 165, 4)
  63. CLEMENTINE = display.create_pen(255,89,0)
  64. YELLOW = display.create_pen(255, 255, 0)
  65. GREEN = display.create_pen(0,255,0)
  66. GREEN2 = display.create_pen(71, 225, 32)
  67. CYAN = display.create_pen(0,255,255)
  68. MAGENTA = display.create_pen(255,0,255)
  69. BLUE = display.create_pen(20,0,255)
  70. WHITE = display.create_pen(255, 255, 255)
  71. GREY = display.create_pen(75, 75, 75)
  72. DKGREY = display.create_pen(20,20,35)
  73. BLACK = display.create_pen(0, 0, 0)
  74.  
  75. colours = [BLUE,RED,PINK,PINK2,ORANGE,CLEMENTINE,YELLOW,GREEN,GREEN2,CYAN,MAGENTA]
  76. col_leng = len(colours)
  77.  
  78. # Pico Vector setup section
  79. vector = PicoVector(display)
  80. vector.set_antialiasing(ANTIALIAS_FAST)
  81. t = Transform()
  82.  
  83. vector.set_font("Roboto-Medium.af", 54)
  84. vector.set_font_letter_spacing(100)
  85. vector.set_font_word_spacing(100)
  86. vector.set_transform(t)
  87.  
  88. vector.set_font_size(20)
  89.  
  90. # A few procedures to be used later
  91.  
  92. def clean(): # Clear the screen to Black
  93.     display.set_pen(BLACK)
  94.     display.clear()
  95.  
  96. def face(hours,mins,secs,hcol,mcol,scol):   # This one majority of the work
  97.  
  98.     cx = int(WIDTH /2)  # Centre of clock
  99.     cy = int(HEIGHT /2)
  100.     l = cy -1             # Max radius
  101.  
  102.     r1 = int(l * 0.62)
  103.     r2 = int(l * 0.58)   # minutes
  104.     r3 = int(l * 0.44)
  105.     r4 = int(l * 0.41)   # hours
  106.     r5 = int(l * 0.05)
  107.    
  108.     # SECONDS
  109.     limit = secs * 6 + 1
  110.     stop = 360
  111.     if secs == 0:   # Ben's adjustment
  112.         limit = 999
  113.         stop = 366
  114.     for angle in range(0,stop,6):
  115.         display.set_pen(minor)            
  116.         if (angle < limit) and (angle > 0):
  117.             display.set_pen(scol)
  118.                
  119.         if thin :
  120.             # Thin
  121.             yy = -int(round(l * math.cos(math.radians(angle))))
  122.             xx = int(round(l * math.sin(math.radians(angle))))    
  123.             display.line(cx,cy,cx+xx,cy+yy)
  124.         else:
  125.             # Thick
  126.             yyp = -int(round(l * math.cos(math.radians(angle+st))))
  127.             xxp = int(round(l * math.sin(math.radians(angle+st))))
  128.             yym = -int(round(l * math.cos(math.radians(angle-st))))
  129.             xxm = int(round(l * math.sin(math.radians(angle-st))))
  130.             display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  131.            
  132.         if (secs == 0) and secspecial: # Special case
  133.             display.set_pen(major)
  134.             angle = 0
  135.             if thin :
  136.                 # Thin
  137.                 yy = -int(round(l * math.cos(math.radians(angle))))
  138.                 xx = int(round(l * math.sin(math.radians(angle))))    
  139.                 display.line(cx,cy,cx+xx,cy+yy)
  140.             else:
  141.                 # Thick
  142.                 yyp = -int(round(l * math.cos(math.radians(angle+st))))
  143.                 xxp = int(round(l * math.sin(math.radians(angle+st))))
  144.                 yym = -int(round(l * math.cos(math.radians(angle-st))))
  145.                 xxm = int(round(l * math.sin(math.radians(angle-st))))
  146.                 display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  147.                    
  148.     display.set_pen(BLACK)
  149.     display.circle(cx,cy,r1)
  150.  
  151.     # MINUTES
  152.     l = r2
  153.     limit = mins * 6 + 1
  154.     stop = 360
  155.     if mins == 0 and (secs == 0):   # Ben's adjustment
  156.         limit = 999
  157.         stop = 366
  158.  
  159.     for angle in range(0,stop,6):
  160.         display.set_pen(minor)
  161.         if (angle < limit) and (angle > 0):
  162.             display.set_pen(mcol)
  163.         if thin:
  164.             # Thin
  165.             yy = -int(round(l * math.cos(math.radians(angle))))
  166.             xx = int(round(l * math.sin(math.radians(angle))))
  167.             display.line(cx,cy,cx+xx,cy+yy)
  168.         else:
  169.             # Thick
  170.             yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  171.             xxp = int(round(l * math.sin(math.radians(angle+mt))))
  172.             yym = -int(round(l * math.cos(math.radians(angle-mt))))
  173.             xxm = int(round(l * math.sin(math.radians(angle-mt))))
  174.             display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  175.        
  176.         # Needed if you consider zero minutes need to be shown
  177.         if (mins == 0) and minspecial and (secs == 0): # Special case
  178.             display.set_pen(major)
  179.             angle = 0
  180.             if thin:
  181.                 # Thin
  182.                 yy = -int(round(l * math.cos(math.radians(angle))))
  183.                 xx = int(round(l * math.sin(math.radians(angle))))
  184.                 display.line(cx,cy,cx+xx,cy+yy)
  185.             else:
  186.                 # Thick
  187.                 yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  188.                 xxp = int(round(l * math.sin(math.radians(angle+mt))))
  189.                 yym = -int(round(l * math.cos(math.radians(angle-mt))))
  190.                 xxm = int(round(l * math.sin(math.radians(angle-mt))))
  191.                 display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  192.        
  193.     display.set_pen(BLACK)
  194.     display.circle(cx,cy,r3)
  195.  
  196.     # HOURS
  197.     l = r5
  198.     lh = r4
  199.     ht = 12
  200.     display.set_pen(hcol)
  201.     for h in range(1,13,1):
  202.         angle = h * 30
  203.         display.set_pen(minor)
  204.         if h <= hours:
  205.             display.set_pen(major)
  206.        
  207.         yy = -int(round(l * math.cos(math.radians(angle))))
  208.         xx = int(round(l * math.sin(math.radians(angle))))
  209.        
  210.         yyp = -int(round(lh * math.cos(math.radians(angle+ht))))
  211.         xxp = int(round(lh * math.sin(math.radians(angle+ht))))
  212.         yym = -int(round(lh * math.cos(math.radians(angle-ht))))
  213.         xxm = int(round(lh * math.sin(math.radians(angle-ht))))
  214.         display.triangle(cx+xx,cy+yy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  215.  
  216.     if numbers:  # TESTING and Learning "+" and "-" control on qwstpad
  217.         display.set_pen(YELLOW)
  218.         display.text("M: "+str(mins),5,5,90,3)
  219.         display.text("S: "+str(secs),420,5,90,3)
  220.         display.text("H: "+str(hours),5,50,100,3)
  221.         display.set_pen(DKGREY)
  222.  
  223.         # Using vector font
  224.         vector.set_font_size(40)
  225. #        display.set_pen(RED)  # for testing
  226.         vector.text("9", 149,253)  # ("Text", x,y)
  227.         vector.text("3",313,253)
  228.         vector.text("6",232,330)
  229.         vector.set_font_size(32)
  230.         vector.text("12",223,171)
  231.                
  232.     presto.update()
  233.  
  234. def face2(mins,secs,mcol,scol):   # Draw countdown face
  235.     secspecial = True
  236.     cx = int(WIDTH /2)  # Centre of clock
  237.     cy = int(HEIGHT /2)
  238.     l = cy -1             # Max radius
  239.     st = 1.9
  240.     mt = 1.7
  241.     r1 = int(l * 0.62)
  242.     r2 = int(l * 0.58)   # minutes
  243.     r3 = int(l * 0.44)
  244.     r4 = int(l * 0.41)   # hours
  245.     r5 = int(l * 0.05)
  246.    
  247.     # SECONDS
  248.     limit = secs * 6 + 1
  249.     stop = 360
  250.     if secs == 60:   # Ben's adjustment
  251.         limit = 999
  252.         stop = 366
  253.     for angle in range(0,stop,6):
  254.         display.set_pen(DKGREY)
  255.         if (angle < limit) and (angle > 0):
  256.             display.set_pen(scol)
  257.  
  258.         # Thick
  259.         yyp = -int(round(l * math.cos(math.radians(angle+st))))
  260.         xxp = int(round(l * math.sin(math.radians(angle+st))))
  261.         yym = -int(round(l * math.cos(math.radians(angle-st))))
  262.         xxm = int(round(l * math.sin(math.radians(angle-st))))
  263.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  264.            
  265.         if (secs == 0): # Special case
  266.             display.set_pen(mcol)
  267.             angle = 0
  268.            
  269.         # Thick
  270.         yyp = -int(round(l * math.cos(math.radians(angle+st))))
  271.         xxp = int(round(l * math.sin(math.radians(angle+st))))
  272.         yym = -int(round(l * math.cos(math.radians(angle-st))))
  273.         xxm = int(round(l * math.sin(math.radians(angle-st))))
  274.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  275.                    
  276.     display.set_pen(BLACK)
  277.     display.circle(cx,cy,r1)
  278.  
  279.     # MINUTES
  280.     l = r2
  281.     limit = mins * 6 + 1
  282.     stop = 360
  283.     if mins == 0 and (secs == 0):   # Ben's adjustment
  284.         limit = 999
  285.         stop = 366
  286.  
  287.     for angle in range(0,stop,6):
  288.         display.set_pen(DKGREY)
  289.         if (angle < limit) and (angle > 0):
  290.             display.set_pen(mcol)
  291.  
  292.         # Thick
  293.         yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  294.         xxp = int(round(l * math.sin(math.radians(angle+mt))))
  295.         yym = -int(round(l * math.cos(math.radians(angle-mt))))
  296.         xxm = int(round(l * math.sin(math.radians(angle-mt))))
  297.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  298.  
  299.         # Thick
  300.         yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  301.         xxp = int(round(l * math.sin(math.radians(angle+mt))))
  302.         yym = -int(round(l * math.cos(math.radians(angle-mt))))
  303.         xxm = int(round(l * math.sin(math.radians(angle-mt))))
  304.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  305.        
  306.     display.set_pen(BLACK)
  307.     display.circle(cx,cy,r3)
  308.  
  309.     presto.update()
  310. # == End of face2
  311.  
  312. def wait(ss): # ss in seconds
  313.     now = time.ticks_ms()
  314.     future = time.ticks_ms() + ss *1000
  315.     while now < future:
  316.         now = time.ticks_ms()
  317.  
  318. # ========== SET TIME 2 - COUNTDOWN TIMER SECTION END ==========================
  319.  
  320. def set_time2():
  321.     qwstpad.set_leds(2)  # qw/stpad LEDS off - set time indication
  322.     p = 1
  323.     val[p] = 2
  324.     show_vals(p,val)
  325.     presto.update()
  326.  
  327.     buttons = qwstpad.read_buttons()
  328.     while buttons["A"] == False: # HALT loop with button'A'
  329.         clean()
  330.  
  331.         # Read all the buttons from the qwstpad
  332.         buttons = qwstpad.read_buttons()
  333.         if buttons["U"] == True:
  334.             val[p] = val[p] + 1
  335.             if val[p] > 59:
  336.                 val[p] = 59
  337.         elif buttons["D"] == True:
  338.             val[p] = val[p] - 1
  339.             if val[p] < 1:
  340.                 val[p] = 1
  341.         elif buttons["R"] == True:
  342.             val[p] = val[p] + 5
  343.             if val[p] > 59:
  344.                 val[p] = 59        
  345.         elif buttons["L"] == True:
  346.             val[p] = val[p] - 5
  347.             if val[p] < 1:
  348.                 val[p] = 1
  349.                
  350.         # Show the changed value
  351.         if p == 0:
  352.             mcol = GREEN
  353.             hcol = RED            
  354.         else:
  355.             mcol = RED
  356.             hcol = GREEN
  357.         show_mins(val[1],mcol)
  358.  
  359.         show_vals(p,val)
  360.         presto.update()
  361.        
  362.         # Wait for button release
  363.         while (buttons["U"]) or (buttons["D"]) :
  364.             buttons = qwstpad.read_buttons()
  365.         time.sleep(0.1)
  366.  
  367.     # "A" has been pressed - return the values
  368.     clean()
  369.     presto.update()
  370.     h = val[0]
  371.     m = val[1]
  372.     s = 0
  373.     qwstpad.set_leds(0)  # qw/stpad LEDS off
  374.     print(m)
  375.     return (m)
  376.  
  377. # ========== SET TIME 2 COUNTDOWN TIMER SECTION END ==========================
  378.  
  379.  
  380.  
  381. def countdown():
  382. # ################### Countdown running loop ######################
  383. #  Time control Extras ===============
  384.     tsecs = 0
  385.     tmins = set_time2()
  386. #    tmins = 2
  387.     countrunning = True
  388.     while countrunning:    
  389.         now = time.time()
  390.         old_time = now
  391.        
  392.         clean()
  393.         if tsecs == 0:
  394.             tsecs = 60
  395.             tmins = tmins - 1
  396.         face2(tmins,tsecs,GREEN,GREEN)
  397.         tsecs = tsecs - 1
  398.         print(str(tmins),str(tsecs))
  399.         if (tmins == 0) and (tsecs == 0):
  400.             countrunning = False
  401.                
  402.         buttons = qwstpad.read_buttons()
  403.         if (buttons["X"]):    # Stop timer
  404.             break
  405.         gc.collect()
  406.        
  407.         # Time control - Wait for next second
  408.         while old_time == now:        
  409.             now = time.time()
  410.         old_time = now
  411.  
  412.     for i in range(8):
  413.         display.set_pen(RED)
  414.         display.clear()
  415.         presto.update()
  416.         wait(0.2)
  417.         display.set_pen(BLACK)
  418.         display.clear()
  419.         presto.update()
  420.         wait(0.2)
  421.    
  422.     return
  423.  
  424. # ============= SET CLOCK TIME SECTION =================================
  425.  
  426. def show_vals(cur,val):
  427.     for i in range(2):
  428.         xx = 20 + i * 60
  429.         display.set_pen(RED)
  430.         if cur == i:
  431.             display.set_pen(YELLOW)
  432.         display.text(str(val[i]),xx,400,200,3)
  433.  
  434. def show_mins(m,c):
  435.     cx = int(WIDTH /2)  # Centre of clock
  436.     cy = int(HEIGHT /2)
  437.     l = cy              # Max radius
  438.  
  439.     r1 = int(l * 0.62)
  440.     r2 = int(l * 0.58)   # minutes
  441.     r3 = int(l * 0.44)
  442.     r4 = int(l * 0.41)   # hours
  443.     r5 = int(l * 0.05)
  444.  
  445.     angle = m*6 + 1
  446.     l = r2
  447.     mt = 1.7 # minutes thickness
  448.     st = 1.9 # seconds thickness
  449.    
  450.     # Empty minutes
  451.     for angle2 in range(0,360,6):
  452.         display.set_pen(minor)
  453.         if angle2 % 5 == 0:  # Indicate 5 min intervals
  454.             display.set_pen(GREY)
  455.            
  456.         # Thick
  457.         yyp = -int(round(l * math.cos(math.radians(angle2+mt))))
  458.         xxp = int(round(l * math.sin(math.radians(angle2+mt))))
  459.         yym = -int(round(l * math.cos(math.radians(angle2-mt))))
  460.         xxm = int(round(l * math.sin(math.radians(angle2-mt))))
  461.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  462.    
  463.     display.set_pen(c)
  464.     yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  465.     xxp = int(round(l * math.sin(math.radians(angle+mt))))
  466.     yym = -int(round(l * math.cos(math.radians(angle-mt))))
  467.     xxm = int(round(l * math.sin(math.radians(angle-mt))))
  468.     display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  469.     display.set_pen(BLACK)
  470.     display.circle(cx,cy,r3)
  471.  
  472. def show_hours(h,c):
  473.    
  474.     cx = int(WIDTH /2)  # Centre of clock
  475.     cy = int(HEIGHT /2)
  476.     l = cy              # Max radius
  477.     r1 = int(l * 0.62)
  478.     r2 = int(l * 0.58)
  479.     r3 = int(l * 0.44)
  480.     r4 = int(l * 0.41)
  481.     r5 = int(l * 0.05)
  482.     l = r5
  483.     lh = r4
  484.     ht = 12
  485.        
  486.     display.set_pen(c)    
  487.     angle = h * 30
  488.    
  489.     yy = -int(round(l * math.cos(math.radians(angle))))
  490.     xx = int(round(l * math.sin(math.radians(angle))))
  491.     yyp = -int(round(lh * math.cos(math.radians(angle+ht))))
  492.     xxp = int(round(lh * math.sin(math.radians(angle+ht))))
  493.     yym = -int(round(lh * math.cos(math.radians(angle-ht))))
  494.     xxm = int(round(lh * math.sin(math.radians(angle-ht))))
  495.     display.triangle(cx+xx,cy+yy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  496.  
  497. def set_time():
  498.     qwstpad.set_leds(2)  # qw/stpad LEDS off - set time indication
  499.     p = 0    
  500.     show_vals(p,val)
  501.     presto.update()
  502.  
  503.     buttons = qwstpad.read_buttons()
  504.     while buttons["A"] == False: # HALT loop with button'A'
  505.         clean()
  506.         diff = 1
  507.         # Read all the buttons from the qwstpad
  508.         buttons = qwstpad.read_buttons()
  509.         if buttons["U"] == True:
  510.             val[p] = val[p] + diff
  511.             if val[p] > maxx[p]:
  512.                 val[p] = minn[p]
  513.         elif buttons["D"] == True:
  514.             val[p] = val[p] - diff
  515.             if val[p] < minn[p]:
  516.                 val[p] = maxx[p]
  517.         elif (buttons["R"] == True) or (buttons["L"] == True):
  518.             if p == 1:
  519.                 p = 0
  520.             else:
  521.                 p = 1
  522.  
  523.         # Show the changed value
  524.         if p == 0:
  525.             mcol = GREEN
  526.             hcol = RED            
  527.         else:
  528.             mcol = RED
  529.             hcol = GREEN
  530.         show_mins(val[1],mcol)
  531.         show_hours(val[0],hcol)
  532.         show_vals(p,val)
  533.         presto.update()
  534.        
  535.         # Wait for button release
  536.         while (buttons["U"]) or (buttons["D"]) or (buttons["L"]) or (buttons["R"]):
  537.             buttons = qwstpad.read_buttons()
  538.         time.sleep(0.1)
  539.  
  540.     # "A" has been pressed - return the values
  541.     clean()
  542.     presto.update()
  543.     h = val[0]
  544.     m = val[1]
  545.     s = 0
  546.     qwstpad.set_leds(0)  # qw/stpad LEDS off
  547.     return (h,m,s)
  548.  
  549.    
  550.  
  551. # ================ Change colour section ===================
  552. def get_col(p,cl ):
  553.     delay = 0.15
  554.     clean()
  555.     display.set_pen(colours[p])
  556.     display.clear()
  557.     presto.update()
  558.     running = True
  559.     while running:
  560.         buttons = qwstpad.read_buttons()
  561.         if buttons["U"] == True:
  562.             p = p + 1
  563.             if p == cl:
  564.                 p = 0
  565.         if buttons["D"] == True:
  566.             p = p - 1
  567.             if p < 0:
  568.                 p = cl -1
  569.         display.set_pen(colours[p])
  570.         print(p)
  571.         display.clear()
  572.         presto.update()
  573.        
  574.         if buttons["B"] == True:
  575.             running = False
  576.         # Wait for button release
  577.         while (buttons["U"] == True) or (buttons["D"] == True):
  578.             buttons = qwstpad.read_buttons()
  579.            
  580.     clean()
  581.     return(p)
  582. # ========== END OF COLOUR CHANGE SECTION ============    
  583.  
  584. # ################# Clock running section #####################
  585.  
  586. # Initial time and colours
  587. hours = 10
  588. mins =59
  589. secs = 55
  590. cp = 0
  591. major = colours[cp]        # Major colour
  592. minor = DKGREY      # Minor colour
  593. maxx = [12,59]
  594. minn = [1,0]
  595. val = [hours,mins]
  596. yy = 200
  597.  
  598. mt = 1.7 # minutes thickness
  599. st = 1.9 # seconds thickness
  600.  
  601. # TESTING FLAGS
  602. thin = False
  603. numbers = False
  604. jump = False
  605. # Show zero secs and mins - FLAGS
  606. minspecial = True
  607. secspecial = False
  608.  
  609. last_second = None    # Extra ======================
  610.  
  611. def fix_time(h,m,s,dif):
  612.     es = dif % 60
  613.     em = dif // 60
  614.     #print (em,es)
  615.     ns = (s + es) % 60
  616.     em = m + em + ((s + es) //60)
  617.     #print (ns, em)
  618.     eh = em // 60
  619.     nh = h + eh
  620.     if nh >= 12:
  621.         nh = nh - 12
  622.     nm = em % 60
  623.     return(nh,nm,ns)
  624.  
  625. # ################### Clock running loop ######################
  626. #  Time control Extras ===============
  627. now = time.time()
  628. old_time = now
  629. while True:    
  630.     t_start = time.ticks_ms()
  631.     now = time.time()
  632.     old_time = now
  633. #    year, month, day, hour, minute, second, _, _ = time.localtime()  
  634.     #end time control TOP========================================
  635.    
  636.     clean()
  637.     face(hours,mins,secs,major,major,major)
  638.     secs = secs + 1
  639.     # Temp JUMP code ============= FOR TESTING =======================
  640.     if jump:
  641.         if secs == 7:
  642.             secs = 55
  643.      #============== =================================================
  644.     if secs == 60:
  645.         secs = 0
  646.         mins = mins + 1
  647.         if mins == 60:
  648.             mins = 0
  649.             hours = hours +1
  650.             if hours == 13:
  651.                 hours = 1
  652.  
  653.     buttons = qwstpad.read_buttons()
  654.     if buttons["Y"] == True:            # Jump to SET TIME section
  655.         val = [hours,mins]              # Start from current time
  656.         hours, mins,secs = set_time()
  657.     elif buttons["-"] == True:
  658.         numbers = False
  659.     elif buttons["+"] == True:
  660.         numbers = True
  661.     elif buttons["X"] == True:
  662.         xh = hours
  663.         xm = mins
  664.         xs = secs
  665.         extime = time.time()
  666.         cp = get_col(cp,col_leng)
  667.         major = colours[cp]
  668.         dif = time.time() - extime
  669.         hours,mins, secs = fix_time(xh,xm,xs,dif)
  670.        
  671.     elif buttons["B"] == True: # Countdown Timer picked
  672.         xh = hours
  673.         xm = mins
  674.         xs = secs
  675.         extime = time.time()    # Grab exit time    
  676.         countdown()
  677.         dif = time.time() - extime
  678.         hours, mins, secs = fix_time(xh,xm,xs,dif) # Adjusted time
  679.        
  680.     gc.collect()
  681.     # Time control - Wait for next second
  682.     while old_time == now:        
  683.         time.sleep_ms(10)
  684.         now = time.time()
  685.     old_time = now
  686.    
  687.     t_end = time.ticks_ms()
  688.     print(f"Took {t_end - t_start}ms")
  689.  
  690.  
  691.  
  692.  
  693.  
Advertisement
Add Comment
Please, Sign In to add comment