Last active
December 4, 2018 21:14
-
-
Save swilson/33025405ed5699f2da0773773ebd51ab to your computer and use it in GitHub Desktop.
HT1635B driver (ported from https://github.com/alotaiba/HT1635B)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import smbus | |
import time | |
bus = smbus.SMBus(1) | |
class HT1635B(): | |
DEVICE_ADDRESS = 0x68 | |
CMD_RAM_W = 0b10000000 | |
CMD_BLINK = 0b10000100 | |
CMD_COM = 0b10001000 | |
CMD_OSC = 0b10100000 | |
CMD_SYSTEM_MODE = 0b10000010 | |
CMD_BRIGHTNESS = 0b11000000 | |
def __init__(self): | |
self._row_data = bytearray(43) | |
def set_row_memory(self, index, data): | |
self._row_data[index] |= data | |
def clear_row_memory(self, index, data): | |
self._row_data[index] &= ~(data) | |
def set_pixel(self, x, y): | |
self.set_row_memory(x, self._get_y_byte_location(y)) | |
def clear_pixel(self, x, y): | |
self.clear_row_memory(x, self._get_y_byte_location(y)) | |
def clear(self): | |
self._row_data = bytearray(43) | |
def render(self): | |
data = list() | |
data.append(0) | |
data.extend(self._row_data[:30]) | |
bus.write_i2c_block_data(self.DEVICE_ADDRESS, self.CMD_RAM_W, data) | |
data = list() | |
data.append(0x3c) | |
data.extend(self._row_data[30:]) | |
bus.write_i2c_block_data(self.DEVICE_ADDRESS, self.CMD_RAM_W, data) | |
# Power-on default is highest brightness (15) | |
# 0-lowest to 15-highest | |
def set_brightness(self, brightness): | |
bus.write_byte_data(self.DEVICE_ADDRESS, self.CMD_BRIGHTNESS, brightness) | |
# Power-on default is no blink | |
# 0: No blink | |
# 1: 2Hz blink (2 blinks per second) fastest | |
# 2: 1Hz blink (1 blink per second) normal | |
# 3: 0.5Hz blink (1 second on/1 second off) slow | |
def set_blinking(self, speed): | |
bus.write_byte_data(self.DEVICE_ADDRESS, self.CMD_BLINK, speed) | |
# Power-on default is N-MOS | |
# 0: N-MOS | |
# 1: P-MOS | |
def set_com(self, option): | |
bus.write_byte_data(self.DEVICE_ADDRESS, self.CMD_COM, option) | |
# Power-on default is RC master mode 0 (4) | |
# 0-3: Slave mode, use external OSC, OSC pin input, Sync pin input | |
# 4 - RC master mode 0, use on chip OSC, OSC pin Hi-Z, Sync pin high | |
# 5 - RC master mode 1, use on chip OSC, OSC pin output, Sync pin output | |
# 6 - EXT CLK master mode 0, use external OSC, OSC pin input, Sync pin high | |
# 7 - EXT CLK master mode 1, use external OSC, OSC pin input, Sync pin output | |
# | |
def set_osc(self, mode): | |
bus.write_byte_data(self.DEVICE_ADDRESS, self.CMD_OSC, mode) | |
# Power-on default is System disabled, LED off (0-1) | |
# 0-1: System disabled, LED off | |
# 2 - System enabled, LED off | |
# 3 - System enabled, LED on | |
def set_system_mode(self, mode): | |
bus.write_byte_data(self.DEVICE_ADDRESS, self.CMD_SYSTEM_MODE, mode) | |
def _get_y_byte_location(self, y): | |
firstBit = 0b10000000 | |
yBitLocationInByte = y % 8 | |
return (firstBit >> yBitLocationInByte) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment