# @name Clock_M # @desc Big pixel clock HH:MM # @author Avemer # @version 1.0 class BigClock var BLINK_COLON var CLOCK_COLOR def init() # COLON SETTINGS # 1 = colon blinks # 0 = colon is always on self.BLINK_COLON = 1 # Clock Color # 0xFFFFFF = White # 0xFF0000 = Red # 0x00FF00 = Green # 0x0000FF = Blue # 0xFFFF00 = Yellow # 0x00FFFF = Cyan # 0xFF00FF = Purple self.CLOCK_COLOR = 0xFFFFFF end # LOOP # The screen updates draw() automatically. def loop() end # DRAWING A SINGLE PIXEL # x = horizontal coordinate # y = vertical coordinate # In reality, we add +1 to Y, # so all digits are shifted down by one line. # AWTRIX Screen = 32 x 8 pixels. def p(x, y) pixel(x, y + 1, self.CLOCK_COLOR) end # DRAWING A DIGIT # x = left coordinate of the digit # n = which digit to draw: 0..9 # Each digit is 6 x 7 pixels in size. # Relative coordinates: # x+0 x+1 x+2 x+3 x+4 # # y=0 █ █ █ █ █ # y=1 █ █ █ █ █ # y=2 █ █ █ █ █ # y=3 █ █ █ █ █ # y=4 █ █ █ █ █ # y=5 █ █ █ █ █ # y=6 █ █ █ █ █ # p() then automatically adds +1 to Y. def digit(x, n) # DIGIT 0 if n == 0 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x,1) self.p(x+4,1) self.p(x,2) self.p(x+4,2) self.p(x,3) self.p(x+4,3) self.p(x,4) self.p(x+4,4) self.p(x,5) self.p(x+4,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) # DIGIT 1 elif n == 1 self.p(x+1,1) self.p(x+2,0) self.p(x+2,1) self.p(x+2,2) self.p(x+2,3) self.p(x+2,4) self.p(x+2,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # DIGIT 2 elif n == 2 self.p(x,1) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,1) self.p(x+4,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x,4) self.p(x,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # DIGIT 3 elif n == 3 self.p(x,1) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,1) self.p(x+4,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,4) self.p(x+4,5) self.p(x,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) # DIGIT 4 elif n == 4 self.p(x,3) self.p(x+1,2) self.p(x+2,1) self.p(x+3,0) self.p(x,4) self.p(x+1,4) self.p(x+2,4) self.p(x+3,4) self.p(x+4,4) self.p(x+3,1) self.p(x+3,2) self.p(x+3,3) self.p(x+3,4) self.p(x+3,5) self.p(x+3,6) # DIGIT 5 elif n == 5 self.p(x,0) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x,1) self.p(x,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,4) self.p(x+4,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) # DIGIT 6 elif n == 6 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,1) self.p(x,1) self.p(x,2) self.p(x,3) self.p(x,4) self.p(x,5) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,4) self.p(x+4,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) # DIGIT 7 elif n == 7 self.p(x,0) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+4,1) self.p(x+4,2) self.p(x+3,3) self.p(x+2,4) self.p(x+2,5) self.p(x+2,6) # DIGIT 8 elif n == 8 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x,1) self.p(x+4,1) self.p(x,2) self.p(x+4,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x,4) self.p(x+4,4) self.p(x,5) self.p(x+4,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) # DIGIT 9 elif n == 9 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x,1) self.p(x+4,1) self.p(x,2) self.p(x+4,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,4) self.p(x+4,5) self.p(x,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) end end # COLON : # x = horizontal coordinate of the colon # Two dots are used: # top dot = Y 2 # bottom dot = Y 4 # Function p() adds +1 to Y, # so they are actually in rows 3 and 5. def colon(x) # If blinking is enabled if self.BLINK_COLON == 1 var s = second() # Even second — show it if s % 2 == 0 self.p(x,1) self.p(x+1,1) self.p(x,2) self.p(x+1,2) self.p(x,4) self.p(x+1,4) self.p(x,5) self.p(x+1,5) end # If blinking is disabled — show it constantly else self.p(x,1) self.p(x+1,1) self.p(x,2) self.p(x+1,2) self.p(x,4) self.p(x+1,4) self.p(x,5) self.p(x+1,5) end end # MAIN CLOCK DRAWING def draw() clear() # GET CURRENT TIME var h = hour() var m = minute() # SPLIT HOURS AND MINUTES INTO INDIVIDUAL DIGITS # For example: # 23:47 # h = 23 # m = 47 # h1 = 2 # h2 = 3 # m1 = 4 # m2 = 7 var h1 = int(h / 10) var h2 = h % 10 var m1 = int(m / 10) var m2 = m % 10 # POSITIONS ON SCREEN # Screen: 32 x 8 pixels # Hours — first digit self.digit(1, h1) # Hours — second digit self.digit(8, h2) # Colon self.colon(15) # Minutes — first digit self.digit(19, m1) # Minutes — second digit self.digit(26, m2) end # BUTTON def on_button(btn) end end return BigClock()