2022-12-23 16:15:35 -05:00
|
|
|
# There are 4 different types of patterns used when generating a digit that is
|
|
|
|
# to be placed in a rectangle 3X5 pixels. Combinations of these are used to
|
|
|
|
# create a number pattern such as:
|
2022-12-23 11:26:50 -05:00
|
|
|
# * * *
|
|
|
|
# *
|
|
|
|
# * * *
|
|
|
|
# * *
|
|
|
|
# * * *
|
2022-12-23 16:15:35 -05:00
|
|
|
#
|
2022-12-23 11:26:50 -05:00
|
|
|
# 1) * * * Full Row
|
|
|
|
# 2) * * Both Sides
|
|
|
|
# 3) * Right Side
|
|
|
|
# 4) * Left Side
|
|
|
|
class CharacterDisplay:
|
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def __init__(self, unicorn, minX=0, maxX=15):
|
2022-12-23 11:26:50 -05:00
|
|
|
self.unicorn = unicorn
|
2022-12-23 14:57:33 -05:00
|
|
|
self.minX = minX
|
|
|
|
self.maxX = maxX
|
2022-12-23 11:26:50 -05:00
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def displayDigit(self, x, y, digit, color):
|
|
|
|
if digit == 0:
|
|
|
|
self.displayZero(x, y, color)
|
|
|
|
elif digit == 1:
|
|
|
|
self.displayOne(x, y, color)
|
|
|
|
elif digit == 2:
|
|
|
|
self.displayTwo(x, y, color)
|
|
|
|
elif digit == 3:
|
|
|
|
self.displayThree(x, y, color)
|
|
|
|
elif digit == 4:
|
|
|
|
self.displayFour(x, y, color)
|
|
|
|
elif digit == 5:
|
|
|
|
self.displayFive(x, y, color)
|
|
|
|
elif digit == 6:
|
|
|
|
self.displaySix(x, y, color)
|
|
|
|
elif digit == 7:
|
|
|
|
self.displaySeven(x, y, color)
|
|
|
|
elif digit == 8:
|
|
|
|
self.displayEight(x, y, color)
|
|
|
|
elif digit == 9:
|
|
|
|
self.displayNine(x, y, color)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def clearDigit(self, x, y):
|
2022-12-23 11:26:50 -05:00
|
|
|
for y1 in range(y, y-5, -1):
|
2022-12-23 14:57:33 -05:00
|
|
|
for x1 in range(x, x+3):
|
|
|
|
self.setPixel(x1, y1, 0, 0, 0)
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
self.unicorn.show()
|
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def displayTimeDots(self, x, y, color):
|
|
|
|
self.setPixel(x, y-1, *color)
|
|
|
|
self.setPixel(x, y-3, *color)
|
2022-12-23 11:26:50 -05:00
|
|
|
self.unicorn.show()
|
2022-12-23 14:57:33 -05:00
|
|
|
|
2022-12-23 16:15:35 -05:00
|
|
|
def displayZero(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.bothSides(x, y-1, *color)
|
|
|
|
self.bothSides(x, y-2, *color)
|
|
|
|
self.bothSides(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayOne(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.rightSide(x, y, *color)
|
|
|
|
self.rightSide(x, y-1, *color)
|
|
|
|
self.rightSide(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.rightSide(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayTwo(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.rightSide(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.leftSide(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayThree(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.rightSide(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayFour(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.bothSides(x, y, *color)
|
|
|
|
self.bothSides(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.rightSide(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayFive(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.leftSide(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displaySix(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.leftSide(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.bothSides(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displaySeven(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.rightSide(x, y-1, *color)
|
|
|
|
self.rightSide(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.rightSide(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayEight(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.bothSides(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.bothSides(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def displayNine(self, x, y, color):
|
|
|
|
self.clearDigit(x, y)
|
|
|
|
self.fullLine(x, y, *color)
|
|
|
|
self.bothSides(x, y-1, *color)
|
|
|
|
self.fullLine(x, y-2, *color)
|
|
|
|
self.rightSide(x, y-3, *color)
|
|
|
|
self.fullLine(x, y-4, *color)
|
|
|
|
|
|
|
|
def fullLine(self, start, row, r, g, b):
|
|
|
|
for x in range(start, start+3):
|
|
|
|
self.setPixel(x, row, r, g, b)
|
|
|
|
|
|
|
|
def bothSides(self, start, row, r, g, b):
|
|
|
|
self.setPixel(start, row, r, g, b)
|
|
|
|
self.setPixel(start+2, row, r, g, b)
|
|
|
|
|
|
|
|
def leftSide(self, start, row, r, g, b):
|
|
|
|
self.setPixel(start, row, r, g, b)
|
|
|
|
|
|
|
|
def rightSide(self, start, row, r, g, b):
|
|
|
|
self.setPixel(start+2, row, r, g, b)
|
|
|
|
|
2022-12-23 14:57:33 -05:00
|
|
|
def setPixel(self, x, y, r, g, b):
|
|
|
|
if x >= self.minX and x <= self.maxX:
|
|
|
|
self.unicorn.set_pixel(x, y, r, g, b)
|