Skip to content

Commit 7a3caa5

Browse files
Fix startup rotation math
1 parent 3cae2d3 commit 7a3caa5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Matrix_Portal_Moon_Clock/code.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ def next_moon_data(datetime, utc_offset):
172172
DISPLAY = MATRIX.display
173173
ACCEL = adafruit_lis3dh.LIS3DH_I2C(busio.I2C(board.SCL, board.SDA),
174174
address=0x19)
175-
ROTATE = (int(((math.atan2(-ACCEL.acceleration.y, -ACCEL.acceleration.x) +
176-
math.pi) / (math.pi * 2) - 0.125) * 4) % 4) * 90
177-
DISPLAY.rotation = ROTATE
175+
DISPLAY.rotation = (int(((math.atan2(-ACCEL.acceleration.y,
176+
-ACCEL.acceleration.x) + math.pi) /
177+
(math.pi * 2) + 0.875) * 4) % 4) * 90
178178

179179
LARGE_FONT = bitmap_font.load_font('/fonts/helvB12.bdf')
180180
SMALL_FONT = bitmap_font.load_font('/fonts/helvR10.bdf')
@@ -189,7 +189,7 @@ def next_moon_data(datetime, utc_offset):
189189
# Element 0 is a stand-in item, later replaced with the moon phase bitmap
190190
# pylint: disable=bare-except
191191
try:
192-
FILENAME = 'moon/splash-' + str(ROTATE) + '.bmp'
192+
FILENAME = 'moon/splash-' + str(DISPLAY.rotation) + '.bmp'
193193
BITMAP = displayio.OnDiskBitmap(open(FILENAME, 'rb'))
194194
TILE_GRID = displayio.TileGrid(BITMAP,
195195
pixel_shader=displayio.ColorConverter(),)
@@ -339,7 +339,7 @@ def next_moon_data(datetime, utc_offset):
339339
else:
340340
NEXT_EVENT = NEXT_PERIOD.set
341341

342-
if ROTATE in (0, 180): # Horizontal 'landscape' orientation
342+
if DISPLAY.rotation in (0, 180): # Horizontal 'landscape' orientation
343343
CENTER_X = 48 # Text along right
344344
MOON_Y = 0 # Moon at left
345345
TIME_Y = 6 # Time at top right

0 commit comments

Comments
 (0)