Add ability to update colors

This commit is contained in:
Mike Cifelli 2022-12-23 16:15:35 -05:00
parent 688db76bc6
commit 9749f51332
2 changed files with 155 additions and 147 deletions

View File

@ -1,18 +1,16 @@
# There are 4 different types of patterns used when generating
# a number that is to be placed in a rectangle 3X5 pixels. Combinations of these
# are used to create a number pattern such as:
# 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:
# * * *
# *
# * * *
# * *
# * * *
#
# 1) * * * Full Row
# 2) * * Both Sides
# 3) * Right Side
# 4) * Left Side
class CharacterDisplay:
def __init__(self, unicorn, minX=0, maxX=15):
@ -20,136 +18,136 @@ class CharacterDisplay:
self.minX = minX
self.maxX = maxX
def fullLine(self, start, row):
for x in range(start, start+3):
self.setPixel(x, row, 255, 0, 0)
def bothSides(self, start, row):
self.setPixel(start, row, 255, 0, 0)
self.setPixel(start+2, row, 255, 0, 0)
def leftSide(self, start, row):
self.setPixel(start, row, 255, 0, 0)
def rightSide(self, start, row):
self.setPixel(start+2, row, 255, 0, 0)
def displayZero(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.bothSides(x, y-1)
self.bothSides(x, y-2)
self.bothSides(x, y-3)
self.fullLine(x, y-4)
def displayOne(self, x, y):
self.clearNumberPixels(x, y)
self.rightSide(x, y)
self.rightSide(x, y-1)
self.rightSide(x, y-2)
self.rightSide(x, y-3)
self.rightSide(x, y-4)
def displayTwo(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.rightSide(x, y-1)
self.fullLine(x, y-2)
self.leftSide(x, y-3)
self.fullLine(x, y-4)
def displayThree(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.rightSide(x, y-1)
self.fullLine(x, y-2)
self.rightSide(x, y-3)
self.fullLine(x, y-4)
def displayFour(self, x, y):
self.clearNumberPixels(x, y)
self.bothSides(x, y)
self.bothSides(x, y-1)
self.fullLine(x, y-2)
self.rightSide(x, y-3)
self.rightSide(x, y-4)
def displayFive(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.leftSide(x, y-1)
self.fullLine(x, y-2)
self.rightSide(x, y-3)
self.fullLine(x, y-4)
def displaySix(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.leftSide(x, y-1)
self.fullLine(x, y-2)
self.bothSides(x, y-3)
self.fullLine(x, y-4)
def displaySeven(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.rightSide(x, y-1)
self.rightSide(x, y-2)
self.rightSide(x, y-3)
self.rightSide(x, y-4)
def displayEight(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.bothSides(x, y-1)
self.fullLine(x, y-2)
self.bothSides(x, y-3)
self.fullLine(x, y-4)
def displayNine(self, x, y):
self.clearNumberPixels(x, y)
self.fullLine(x, y)
self.bothSides(x, y-1)
self.fullLine(x, y-2)
self.rightSide(x, y-3)
self.fullLine(x, y-4)
def displayNumber(self, x, y, number):
if number == 0:
self.displayZero(x, y)
elif number == 1:
self.displayOne(x, y)
elif number == 2:
self.displayTwo(x, y)
elif number == 3:
self.displayThree(x, y)
elif number == 4:
self.displayFour(x, y)
elif number == 5:
self.displayFive(x, y)
elif number == 6:
self.displaySix(x, y)
elif number == 7:
self.displaySeven(x, y)
elif number == 8:
self.displayEight(x, y)
elif number == 9:
self.displayNine(x, y)
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)
self.unicorn.show()
def clearNumberPixels(self, x, y):
def clearDigit(self, x, y):
for y1 in range(y, y-5, -1):
for x1 in range(x, x+3):
self.setPixel(x1, y1, 0, 0, 0)
self.unicorn.show()
def displayTimeDots(self, x, y):
self.setPixel(x, y-1, 255, 0, 0)
self.setPixel(x, y-3, 255, 0, 0)
def displayTimeDots(self, x, y, color):
self.setPixel(x, y-1, *color)
self.setPixel(x, y-3, *color)
self.unicorn.show()
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)
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)

View File

@ -4,15 +4,21 @@ from datetime import datetime
class TimeDisplay:
def __init__(self, characterDisplay, topRow):
self.currentHour = [-1, -1]
self.currentMinute = [-1, -1]
self.characterDisplay = characterDisplay
self.topRow = topRow
self.currentHour = [-1, -1]
self.currentMinute = [-1, -1]
self.currentColor = (0, 0, 0)
self.color = (255, 80, 0)
self.hourStartColumn = -1
self.timeDotsColumn = 7
self.minuteStartColumn = 9
self.characterDisplay.displayTimeDots(self.timeDotsColumn, self.topRow)
self.characterDisplay.displayTimeDots(
x=self.timeDotsColumn,
y=self.topRow,
color=self.color
)
def showTime(self):
self.showHour(self.getHourDigits())
@ -23,40 +29,44 @@ class TimeDisplay:
self.currentHour[0] = hour[0]
if hour[0] == 0:
self.characterDisplay.clearNumberPixels(
self.hourStartColumn,
self.topRow
self.characterDisplay.clearDigit(
x=self.hourStartColumn,
y=self.topRow
)
else:
self.characterDisplay.displayNumber(
self.hourStartColumn,
self.topRow,
hour[0]
self.characterDisplay.displayDigit(
x=self.hourStartColumn,
y=self.topRow,
digit=hour[0],
color=self.color
)
if hour[1] != self.currentHour[1]:
self.currentHour[1] = hour[1]
self.characterDisplay.displayNumber(
self.hourStartColumn + 4,
self.topRow,
hour[1]
self.characterDisplay.displayDigit(
x=self.hourStartColumn + 4,
y=self.topRow,
digit=hour[1],
color=self.color
)
def showMinute(self, minute):
if minute[0] != self.currentMinute[0]:
self.currentMinute[0] = minute[0]
self.characterDisplay.displayNumber(
self.minuteStartColumn,
self.topRow,
minute[0]
self.characterDisplay.displayDigit(
x=self.minuteStartColumn,
y=self.topRow,
digit=minute[0],
color=self.color
)
if minute[1] != self.currentMinute[1]:
self.currentMinute[1] = minute[1]
self.characterDisplay.displayNumber(
self.minuteStartColumn + 4,
self.topRow,
minute[1]
self.characterDisplay.displayDigit(
x=self.minuteStartColumn + 4,
y=self.topRow,
digit=minute[1],
color=self.color
)
def getHourDigits(self):