TonyGo

CLK2v5

Feb 27th, 2026
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.04 KB | Software | 0 0
  1. # CLK2 v5 -  Minute timer added + Time Fix
  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
  25. # Press A to start count-down timer
  26. # Press X to abort the timer and return to normal clock running
  27.  
  28. import gc
  29. import time
  30. from machine import I2C, Pin
  31. import math
  32. from qwstpad import QwSTPad
  33. from presto import Presto
  34. from picovector import ANTIALIAS_FAST, PicoVector, Polygon, Transform
  35.  
  36. # Setup for the Presto display
  37. presto = Presto(full_res=True)
  38. display = presto.display
  39. touch = presto.touch # Activate touch
  40. i2c = I2C(id=0,scl=Pin(41), sda=Pin(40)) # PRESTO
  41.  
  42. # Connect single default I2C address QwSTPad
  43. try:
  44.     qwstpad = QwSTPad(i2c, 0x21)
  45. except OSError:
  46.     print("QwSTPad: Not Connected ... Exiting")
  47.     raise SystemExit
  48.  
  49. # Turn of LED on qw/stpad
  50. qwstpad.set_leds(0)
  51.  
  52. WIDTH, HEIGHT = display.get_bounds()
  53. #WIDTH = 200
  54. #HEIGHT = WIDTH
  55. display.set_font("bitmap8") # Change the font
  56.  
  57. # Create some colours - not all used at the moment
  58. RED = display.create_pen(255,0,0)
  59. PINK = display.create_pen(250, 125, 180)
  60. PINK2 = display.create_pen(247,21,157)
  61. ORANGE = display.create_pen(245, 165, 4)
  62. CLEMENTINE = display.create_pen(255,89,0)
  63. YELLOW = display.create_pen(255, 255, 0)
  64. GREEN = display.create_pen(0,255,0)
  65. GREEN2 = display.create_pen(71, 225, 32)
  66. CYAN = display.create_pen(0,255,255)
  67. MAGENTA = display.create_pen(255,0,255)
  68. BLUE = display.create_pen(20,0,255)
  69. WHITE = display.create_pen(255, 255, 255)
  70. GREY = display.create_pen(75, 75, 75)
  71. DKGREY = display.create_pen(20,20,35)
  72. BLACK = display.create_pen(0, 0, 0)
  73.  
  74. colours = [BLUE,RED,PINK,PINK2,ORANGE,CLEMENTINE,YELLOW,GREEN,GREEN2,CYAN,MAGENTA]
  75. col_leng = len(colours)
  76.  
  77. # Pico Vector setup section
  78. vector = PicoVector(display)
  79. vector.set_antialiasing(ANTIALIAS_FAST)
  80. t = Transform()
  81.  
  82. vector.set_font("Roboto-Medium.af", 54)
  83. vector.set_font_letter_spacing(100)
  84. vector.set_font_word_spacing(100)
  85. vector.set_transform(t)
  86.  
  87. vector.set_font_size(20)
  88.  
  89. # A few procedures to be used later
  90.  
  91. def clean(): # Clear the screen to Black
  92.     display.set_pen(BLACK)
  93.     display.clear()
  94.  
  95. def face(hours,mins,secs,hcol,mcol,scol):   # This one majority of the work
  96.  
  97.     cx = int(WIDTH /2)  # Centre of clock
  98.     cy = int(HEIGHT /2)
  99.     l = cy -1             # Max radius
  100.  
  101.     r1 = int(l * 0.62)
  102.     r2 = int(l * 0.58)   # minutes
  103.     r3 = int(l * 0.44)
  104.     r4 = int(l * 0.41)   # hours
  105.     r5 = int(l * 0.05)
  106.    
  107.     # SECONDS
  108.     limit = secs * 6 + 1
  109.     stop = 360
  110.     if secs == 0:   # Ben's adjustment
  111.         limit = 999
  112.         stop = 366
  113.     for angle in range(0,stop,6):
  114.         display.set_pen(minor)            
  115.         if (angle < limit) and (angle > 0):
  116.             display.set_pen(scol)
  117.                
  118.         if thin :
  119.             # Thin
  120.             yy = -int(round(l * math.cos(math.radians(angle))))
  121.             xx = int(round(l * math.sin(math.radians(angle))))    
  122.             display.line(cx,cy,cx+xx,cy+yy)
  123.         else:
  124.             # Thick
  125.             yyp = -int(round(l * math.cos(math.radians(angle+st))))
  126.             xxp = int(round(l * math.sin(math.radians(angle+st))))
  127.             yym = -int(round(l * math.cos(math.radians(angle-st))))
  128.             xxm = int(round(l * math.sin(math.radians(angle-st))))
  129.             display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  130.            
  131.         if (secs == 0) and secspecial: # Special case
  132.             display.set_pen(major)
  133.             angle = 0
  134.             if thin :
  135.                 # Thin
  136.                 yy = -int(round(l * math.cos(math.radians(angle))))
  137.                 xx = int(round(l * math.sin(math.radians(angle))))    
  138.                 display.line(cx,cy,cx+xx,cy+yy)
  139.             else:
  140.                 # Thick
  141.                 yyp = -int(round(l * math.cos(math.radians(angle+st))))
  142.                 xxp = int(round(l * math.sin(math.radians(angle+st))))
  143.                 yym = -int(round(l * math.cos(math.radians(angle-st))))
  144.                 xxm = int(round(l * math.sin(math.radians(angle-st))))
  145.                 display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  146.                    
  147.     display.set_pen(BLACK)
  148.     display.circle(cx,cy,r1)
  149.  
  150.     # MINUTES
  151.     l = r2
  152.     limit = mins * 6 + 1
  153.     stop = 360
  154.     if mins == 0 and (secs == 0):   # Ben's adjustment
  155.         limit = 999
  156.         stop = 366
  157.  
  158.     for angle in range(0,stop,6):
  159.         display.set_pen(minor)
  160.         if (angle < limit) and (angle > 0):
  161.             display.set_pen(mcol)
  162.         if thin:
  163.             # Thin
  164.             yy = -int(round(l * math.cos(math.radians(angle))))
  165.             xx = int(round(l * math.sin(math.radians(angle))))
  166.             display.line(cx,cy,cx+xx,cy+yy)
  167.         else:
  168.             # Thick
  169.             yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  170.             xxp = int(round(l * math.sin(math.radians(angle+mt))))
  171.             yym = -int(round(l * math.cos(math.radians(angle-mt))))
  172.             xxm = int(round(l * math.sin(math.radians(angle-mt))))
  173.             display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  174.        
  175.         # Needed if you consider zero minutes need to be shown
  176.         if (mins == 0) and minspecial and (secs == 0): # Special case
  177.             display.set_pen(major)
  178.             angle = 0
  179.             if thin:
  180.                 # Thin
  181.                 yy = -int(round(l * math.cos(math.radians(angle))))
  182.                 xx = int(round(l * math.sin(math.radians(angle))))
  183.                 display.line(cx,cy,cx+xx,cy+yy)
  184.             else:
  185.                 # Thick
  186.                 yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  187.                 xxp = int(round(l * math.sin(math.radians(angle+mt))))
  188.                 yym = -int(round(l * math.cos(math.radians(angle-mt))))
  189.                 xxm = int(round(l * math.sin(math.radians(angle-mt))))
  190.                 display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  191.        
  192.     display.set_pen(BLACK)
  193.     display.circle(cx,cy,r3)
  194.  
  195.     # HOURS
  196.     l = r5
  197.     lh = r4
  198.     ht = 12
  199.     display.set_pen(hcol)
  200.     for h in range(1,13,1):
  201.         angle = h * 30
  202.         display.set_pen(minor)
  203.         if h <= hours:
  204.             display.set_pen(major)
  205.        
  206.         yy = -int(round(l * math.cos(math.radians(angle))))
  207.         xx = int(round(l * math.sin(math.radians(angle))))
  208.        
  209.         yyp = -int(round(lh * math.cos(math.radians(angle+ht))))
  210.         xxp = int(round(lh * math.sin(math.radians(angle+ht))))
  211.         yym = -int(round(lh * math.cos(math.radians(angle-ht))))
  212.         xxm = int(round(lh * math.sin(math.radians(angle-ht))))
  213.         display.triangle(cx+xx,cy+yy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  214.  
  215.     if numbers:  # TESTING and Learning "+" and "-" control on qwstpad
  216.         display.set_pen(YELLOW)
  217.         display.text("M: "+str(mins),5,5,90,3)
  218.         display.text("S: "+str(secs),420,5,90,3)
  219.         display.text("H: "+str(hours),5,50,100,3)
  220.         display.set_pen(DKGREY)
  221.         ''' # Using Crude font
  222.        display.text("9",155,235,50,4)
  223.        display.text("3",320,235,50,4)
  224.        display.text("6",238,310,50,4)
  225.        display.text("12",235,155,50,4)
  226.        '''
  227.         # Using vector font
  228.         vector.set_font_size(40)
  229. #        display.set_pen(RED)  # for testing
  230.         vector.text("9", 149,253)  # ("Text", x,y)
  231.         vector.text("3",313,253)
  232.         vector.text("6",232,330)
  233.         vector.set_font_size(32)
  234.         vector.text("12",223,171)
  235.                
  236.     presto.update()
  237.  
  238. def face2(mins,secs,mcol,scol):   # Draw countdown face
  239.     secspecial = True
  240.     cx = int(WIDTH /2)  # Centre of clock
  241.     cy = int(HEIGHT /2)
  242.     l = cy -1             # Max radius
  243.     st = 1.9
  244.     mt = 1.7
  245.     r1 = int(l * 0.62)
  246.     r2 = int(l * 0.58)   # minutes
  247.     r3 = int(l * 0.44)
  248.     r4 = int(l * 0.41)   # hours
  249.     r5 = int(l * 0.05)
  250.    
  251.     # SECONDS
  252.     limit = secs * 6 + 1
  253.     stop = 360
  254.     if secs == 60:   # Ben's adjustment
  255.         limit = 999
  256.         stop = 366
  257.     for angle in range(0,stop,6):
  258.         display.set_pen(DKGREY)
  259.         if (angle < limit) and (angle > 0):
  260.             display.set_pen(scol)
  261.  
  262.         # Thick
  263.         yyp = -int(round(l * math.cos(math.radians(angle+st))))
  264.         xxp = int(round(l * math.sin(math.radians(angle+st))))
  265.         yym = -int(round(l * math.cos(math.radians(angle-st))))
  266.         xxm = int(round(l * math.sin(math.radians(angle-st))))
  267.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  268.            
  269.         if (secs == 0): # Special case
  270.             display.set_pen(mcol)
  271.             angle = 0
  272.            
  273.         # Thick
  274.         yyp = -int(round(l * math.cos(math.radians(angle+st))))
  275.         xxp = int(round(l * math.sin(math.radians(angle+st))))
  276.         yym = -int(round(l * math.cos(math.radians(angle-st))))
  277.         xxm = int(round(l * math.sin(math.radians(angle-st))))
  278.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  279.                    
  280.     display.set_pen(BLACK)
  281.     display.circle(cx,cy,r1)
  282.  
  283.     # MINUTES
  284.     l = r2
  285.     limit = mins * 6 + 1
  286.     stop = 360
  287.     if mins == 0 and (secs == 0):   # Ben's adjustment
  288.         limit = 999
  289.         stop = 366
  290.  
  291.     for angle in range(0,stop,6):
  292.         display.set_pen(DKGREY)
  293.         if (angle < limit) and (angle > 0):
  294.             display.set_pen(mcol)
  295.  
  296.         # Thick
  297.         yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  298.         xxp = int(round(l * math.sin(math.radians(angle+mt))))
  299.         yym = -int(round(l * math.cos(math.radians(angle-mt))))
  300.         xxm = int(round(l * math.sin(math.radians(angle-mt))))
  301.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  302.         '''
  303.        # Needed if you consider zero minutes need to be shown
  304.        if (mins == 0) and minspecial and (secs == 0): # Special case
  305.            display.set_pen(GREEN)
  306.            angle = 0
  307.        '''
  308.         # Thick
  309.         yyp = -int(round(l * math.cos(math.radians(angle+mt))))
  310.         xxp = int(round(l * math.sin(math.radians(angle+mt))))
  311.         yym = -int(round(l * math.cos(math.radians(angle-mt))))
  312.         xxm = int(round(l * math.sin(math.radians(angle-mt))))
  313.         display.triangle(cx,cy,cx+xxp,cy+yyp,cx+xxm,cy+yym)
  314.        
  315.     display.set_pen(BLACK)
  316.     display.circle(cx,cy,r3)
  317.  
  318.     presto.update()
  319. # == End of face2
  320.  
  321. # ========== SET TIME 2 - COUNTDOWN TIMER SECTION END ==========================
  322.  
  323. def set_time2():
  324.     qwstpad.set_leds(2)  # qw/stpad LEDS off - set time indication
  325.     p = 1
  326.     val[p] = 2
  327.     show_vals(p,val)
  328.     presto.update()
  329.  
  330.     buttons = qwstpad.read_buttons()
  331.     while buttons["A"] == False: # HALT loop with button'A'
  332.         clean()
  333.         diff = 1
  334.         # Read all the buttons from the qwstpad
  335.         buttons = qwstpad.read_buttons()
  336.         if buttons["U"] == True:
  337.             val[p] = val[p] + diff
  338.             if val[p] > maxx[p]:
  339.                 val[p] = minn[p]
  340.         elif buttons["D"] == True:
  341.             val[p] = val[p] - diff
  342.             if val[p] < minn[p]:
  343.                 val[p] = maxx[p]
  344.  
  345.         # Show the changed value
  346.         if p == 0:
  347.             mcol = GREEN
  348.             hcol = RED            
  349.         else:
  350.             mcol = RED
  351.             hcol = GREEN
  352.         show_mins(val[1],mcol)
  353. #        show_hours(val[0],hcol)
  354.         show_vals(p,val)
  355.         presto.update()
  356.        
  357.         # Wait for button release
  358.         while (buttons["U"]) or (buttons["D"]) :
  359.             buttons = qwstpad.read_buttons()
  360.         time.sleep(0.1)
  361.  
  362.     # "A" has been pressed - return the values
  363.     clean()
  364.     presto.update()
  365.     h = val[0]
  366.     m = val[1]
  367.     s = 0
  368.     qwstpad.set_leds(0)  # qw/stpad LEDS off
  369.     print(m)
  370.     return (m)
  371.  
  372. # ========== SET TIME 2 COUNTDOWN TIMER SECTION END ==========================
  373.  
  374. def wait(ss): # ss in seconds
  375.     now = time.ticks_ms()
  376.     future = time.ticks_ms() + ss *1000
  377.     while now < future:
  378.         now = time.ticks_ms()
  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