WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ht16k33/ht16k33.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ class HT16K33:
HT16K33_GENERIC_SYSTEM_OFF = 0x20
HT16K33_GENERIC_DISPLAY_ADDRESS = 0x00
HT16K33_GENERIC_CMD_BRIGHTNESS = 0xE0
HT16K33_GENERIC_CMD_BLINK = 0x81
HT16K33_GENERIC_CMD_BLINK = 0x80

# *********** PRIVATE PROPERTIES **********

i2c = None
address = 0
brightness = 15
display_on = 1
flash_rate = 0

# *********** CONSTRUCTOR **********
Expand All @@ -45,10 +46,16 @@ def set_blink_rate(self, rate=0):
Args:
rate (int): The chosen flash rate. Default: 0Hz (no flash).
"""
if rate < 0:
self.display_on = not self.display_on
rate = 0
else:
self.display_on = 1

allowed_rates = (0, 2, 1, 0.5)
assert rate in allowed_rates, "ERROR - Invalid blink rate set in set_blink_rate()"
self.blink_rate = allowed_rates.index(rate) & 0x03
self._write_cmd(self.HT16K33_GENERIC_CMD_BLINK | self.blink_rate << 1)
self._write_cmd(self.HT16K33_GENERIC_CMD_BLINK | self.blink_rate << 1 | self.display_on)

def set_brightness(self, brightness=15):
"""
Expand Down Expand Up @@ -94,11 +101,13 @@ def power_on(self):
"""
self._write_cmd(self.HT16K33_GENERIC_SYSTEM_ON)
self._write_cmd(self.HT16K33_GENERIC_DISPLAY_ON)
display_on = 1

def power_off(self):
"""
Power on the controller and display.
"""
display_on = 0
self._write_cmd(self.HT16K33_GENERIC_DISPLAY_OFF)
self._write_cmd(self.HT16K33_GENERIC_SYSTEM_OFF)

Expand Down