|
23 | 23 | SET_PRECHARGE = const(0xD9)
|
24 | 24 | SET_VCOM_DESEL = const(0xDB)
|
25 | 25 | SET_CHARGE_PUMP = const(0x8D)
|
| 26 | +SET_HWSCROLL_OFF = const(0x2e) |
| 27 | +SET_HWSCROLL_ON = const(0x2f) |
| 28 | +SET_HWSCROLL_RIGHT = const(0x26) |
| 29 | +SET_HWSCROLL_LEFT = const(0x27) |
| 30 | +SET_HWSCROLL_VR = const(0x29) |
| 31 | +SET_HWSCROLL_VL = const(0x2a) |
26 | 32 |
|
27 | 33 | # Subclassing FrameBuffer provides support for graphics primitives
|
28 | 34 | # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
|
29 | 35 | class SSD1306(framebuf.FrameBuffer):
|
| 36 | + FRAMES_2 = 0x07 |
| 37 | + FRAMES_3 = 0x04 |
| 38 | + FRAMES_4 = 0x05 |
| 39 | + FRAMES_5 = 0x00 |
| 40 | + FRAMES_25 = 0x06 |
| 41 | + FRAMES_64 = 0x01 |
| 42 | + FRAMES_128 = 0x02 |
| 43 | + FRAMES_256 = 0x03 |
| 44 | + |
30 | 45 | def __init__(self, width, height, external_vcc):
|
31 | 46 | self.width = width
|
32 | 47 | self.height = height
|
@@ -108,6 +123,49 @@ def show(self):
|
108 | 123 | self.write_cmd(self.pages - 1)
|
109 | 124 | self.write_data(self.buffer)
|
110 | 125 |
|
| 126 | + def clear(self): |
| 127 | + self.fill(0) |
| 128 | + self.show() |
| 129 | + |
| 130 | + def hw_scroll_off(self): |
| 131 | + self.write_cmd(SET_HWSCROLL_OFF) # turn off scroll |
| 132 | + |
| 133 | + def hw_scroll_h( |
| 134 | + self, |
| 135 | + direction=True, # True/False: right/left |
| 136 | + interval=FRAMES_5 # one frame ≓ 9.2ms |
| 137 | + ): |
| 138 | + self.write_cmd(SET_HWSCROLL_OFF) # turn off hardware scroll per SSD1306 datasheet |
| 139 | + if not direction: |
| 140 | + self.write_cmd(SET_HWSCROLL_LEFT) |
| 141 | + else: |
| 142 | + self.write_cmd(SET_HWSCROLL_RIGHT) |
| 143 | + self.write_cmd(0x00) # dummy byte |
| 144 | + self.write_cmd(0x00) # start page = page 0 |
| 145 | + self.write_cmd(interval) # interval |
| 146 | + self.write_cmd(0x07) # end page = page 7 |
| 147 | + self.write_cmd(0x00) # dummy byte |
| 148 | + self.write_cmd(0xff) # dummy byte |
| 149 | + self.write_cmd(SET_HWSCROLL_ON) # activate scroll |
| 150 | + |
| 151 | + def hw_scroll_diag( |
| 152 | + self, |
| 153 | + direction=True, # True/False: right/left |
| 154 | + interval=FRAMES_5, # one frame ≓ 9.2ms |
| 155 | + offset=1 # vertical offset per scroll |
| 156 | + ): |
| 157 | + |
| 158 | + self.write_cmd(SET_HWSCROLL_OFF) # turn off hardware scroll per SSD1306 datasheet |
| 159 | + if not direction: |
| 160 | + self.write_cmd(SET_HWSCROLL_VL) |
| 161 | + else: |
| 162 | + self.write_cmd(SET_HWSCROLL_VR) |
| 163 | + self.write_cmd(0x00) # dummy byte |
| 164 | + self.write_cmd(0x00) # start page = page 0 |
| 165 | + self.write_cmd(interval) # interval |
| 166 | + self.write_cmd(0x07) # end page = page 7 |
| 167 | + self.write_cmd(offset) # vertical offset per scroll |
| 168 | + self.write_cmd(SET_HWSCROLL_ON) # activate scroll |
111 | 169 |
|
112 | 170 | class SSD1306_I2C(SSD1306):
|
113 | 171 | def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
|
|
0 commit comments