Add ability to update colors
This commit is contained in:
parent
688db76bc6
commit
9749f51332
|
@ -1,18 +1,16 @@
|
||||||
# There are 4 different types of patterns used when generating
|
# There are 4 different types of patterns used when generating a digit that is
|
||||||
# a number that is to be placed in a rectangle 3X5 pixels. Combinations of these
|
# to be placed in a rectangle 3X5 pixels. Combinations of these are used to
|
||||||
# are used to create a number pattern such as:
|
# create a number pattern such as:
|
||||||
# * * *
|
# * * *
|
||||||
# *
|
# *
|
||||||
# * * *
|
# * * *
|
||||||
# * *
|
# * *
|
||||||
# * * *
|
# * * *
|
||||||
|
#
|
||||||
# 1) * * * Full Row
|
# 1) * * * Full Row
|
||||||
# 2) * * Both Sides
|
# 2) * * Both Sides
|
||||||
# 3) * Right Side
|
# 3) * Right Side
|
||||||
# 4) * Left Side
|
# 4) * Left Side
|
||||||
|
|
||||||
|
|
||||||
class CharacterDisplay:
|
class CharacterDisplay:
|
||||||
|
|
||||||
def __init__(self, unicorn, minX=0, maxX=15):
|
def __init__(self, unicorn, minX=0, maxX=15):
|
||||||
|
@ -20,136 +18,136 @@ class CharacterDisplay:
|
||||||
self.minX = minX
|
self.minX = minX
|
||||||
self.maxX = maxX
|
self.maxX = maxX
|
||||||
|
|
||||||
def fullLine(self, start, row):
|
def displayDigit(self, x, y, digit, color):
|
||||||
for x in range(start, start+3):
|
if digit == 0:
|
||||||
self.setPixel(x, row, 255, 0, 0)
|
self.displayZero(x, y, color)
|
||||||
|
elif digit == 1:
|
||||||
def bothSides(self, start, row):
|
self.displayOne(x, y, color)
|
||||||
self.setPixel(start, row, 255, 0, 0)
|
elif digit == 2:
|
||||||
self.setPixel(start+2, row, 255, 0, 0)
|
self.displayTwo(x, y, color)
|
||||||
|
elif digit == 3:
|
||||||
def leftSide(self, start, row):
|
self.displayThree(x, y, color)
|
||||||
self.setPixel(start, row, 255, 0, 0)
|
elif digit == 4:
|
||||||
|
self.displayFour(x, y, color)
|
||||||
def rightSide(self, start, row):
|
elif digit == 5:
|
||||||
self.setPixel(start+2, row, 255, 0, 0)
|
self.displayFive(x, y, color)
|
||||||
|
elif digit == 6:
|
||||||
def displayZero(self, x, y):
|
self.displaySix(x, y, color)
|
||||||
self.clearNumberPixels(x, y)
|
elif digit == 7:
|
||||||
self.fullLine(x, y)
|
self.displaySeven(x, y, color)
|
||||||
self.bothSides(x, y-1)
|
elif digit == 8:
|
||||||
self.bothSides(x, y-2)
|
self.displayEight(x, y, color)
|
||||||
self.bothSides(x, y-3)
|
elif digit == 9:
|
||||||
self.fullLine(x, y-4)
|
self.displayNine(x, y, color)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
def clearNumberPixels(self, x, y):
|
def clearDigit(self, x, y):
|
||||||
for y1 in range(y, y-5, -1):
|
for y1 in range(y, y-5, -1):
|
||||||
for x1 in range(x, x+3):
|
for x1 in range(x, x+3):
|
||||||
self.setPixel(x1, y1, 0, 0, 0)
|
self.setPixel(x1, y1, 0, 0, 0)
|
||||||
|
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
def displayTimeDots(self, x, y):
|
def displayTimeDots(self, x, y, color):
|
||||||
self.setPixel(x, y-1, 255, 0, 0)
|
self.setPixel(x, y-1, *color)
|
||||||
self.setPixel(x, y-3, 255, 0, 0)
|
self.setPixel(x, y-3, *color)
|
||||||
self.unicorn.show()
|
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):
|
def setPixel(self, x, y, r, g, b):
|
||||||
if x >= self.minX and x <= self.maxX:
|
if x >= self.minX and x <= self.maxX:
|
||||||
self.unicorn.set_pixel(x, y, r, g, b)
|
self.unicorn.set_pixel(x, y, r, g, b)
|
||||||
|
|
|
@ -4,15 +4,21 @@ from datetime import datetime
|
||||||
class TimeDisplay:
|
class TimeDisplay:
|
||||||
|
|
||||||
def __init__(self, characterDisplay, topRow):
|
def __init__(self, characterDisplay, topRow):
|
||||||
self.currentHour = [-1, -1]
|
|
||||||
self.currentMinute = [-1, -1]
|
|
||||||
self.characterDisplay = characterDisplay
|
self.characterDisplay = characterDisplay
|
||||||
self.topRow = topRow
|
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.hourStartColumn = -1
|
||||||
self.timeDotsColumn = 7
|
self.timeDotsColumn = 7
|
||||||
self.minuteStartColumn = 9
|
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):
|
def showTime(self):
|
||||||
self.showHour(self.getHourDigits())
|
self.showHour(self.getHourDigits())
|
||||||
|
@ -23,40 +29,44 @@ class TimeDisplay:
|
||||||
self.currentHour[0] = hour[0]
|
self.currentHour[0] = hour[0]
|
||||||
|
|
||||||
if hour[0] == 0:
|
if hour[0] == 0:
|
||||||
self.characterDisplay.clearNumberPixels(
|
self.characterDisplay.clearDigit(
|
||||||
self.hourStartColumn,
|
x=self.hourStartColumn,
|
||||||
self.topRow
|
y=self.topRow
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.characterDisplay.displayNumber(
|
self.characterDisplay.displayDigit(
|
||||||
self.hourStartColumn,
|
x=self.hourStartColumn,
|
||||||
self.topRow,
|
y=self.topRow,
|
||||||
hour[0]
|
digit=hour[0],
|
||||||
|
color=self.color
|
||||||
)
|
)
|
||||||
|
|
||||||
if hour[1] != self.currentHour[1]:
|
if hour[1] != self.currentHour[1]:
|
||||||
self.currentHour[1] = hour[1]
|
self.currentHour[1] = hour[1]
|
||||||
self.characterDisplay.displayNumber(
|
self.characterDisplay.displayDigit(
|
||||||
self.hourStartColumn + 4,
|
x=self.hourStartColumn + 4,
|
||||||
self.topRow,
|
y=self.topRow,
|
||||||
hour[1]
|
digit=hour[1],
|
||||||
|
color=self.color
|
||||||
)
|
)
|
||||||
|
|
||||||
def showMinute(self, minute):
|
def showMinute(self, minute):
|
||||||
if minute[0] != self.currentMinute[0]:
|
if minute[0] != self.currentMinute[0]:
|
||||||
self.currentMinute[0] = minute[0]
|
self.currentMinute[0] = minute[0]
|
||||||
self.characterDisplay.displayNumber(
|
self.characterDisplay.displayDigit(
|
||||||
self.minuteStartColumn,
|
x=self.minuteStartColumn,
|
||||||
self.topRow,
|
y=self.topRow,
|
||||||
minute[0]
|
digit=minute[0],
|
||||||
|
color=self.color
|
||||||
)
|
)
|
||||||
|
|
||||||
if minute[1] != self.currentMinute[1]:
|
if minute[1] != self.currentMinute[1]:
|
||||||
self.currentMinute[1] = minute[1]
|
self.currentMinute[1] = minute[1]
|
||||||
self.characterDisplay.displayNumber(
|
self.characterDisplay.displayDigit(
|
||||||
self.minuteStartColumn + 4,
|
x=self.minuteStartColumn + 4,
|
||||||
self.topRow,
|
y=self.topRow,
|
||||||
minute[1]
|
digit=minute[1],
|
||||||
|
color=self.color
|
||||||
)
|
)
|
||||||
|
|
||||||
def getHourDigits(self):
|
def getHourDigits(self):
|
||||||
|
|
Loading…
Reference in New Issue