Added rotate180

Added a `rotate180()` function and its accessory, `invert()`

See [this repo](https://github.com/Kongduino/ssd1306_mp).
pull/7/head
Kongduino 2023-01-08 16:17:25 +08:00 zatwierdzone przez GitHub
rodzic 9582998cd8
commit 111e6505bb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 16 dodań i 0 usunięć

Wyświetl plik

@ -3,6 +3,14 @@
from micropython import const
import framebuf
# Kongduino: 2023/01/08 Added rotate180
# invert: used with rotate180. moves bits 0-7 to 7-0
def invert(a):
c = 0
for i in range (0, 8):
b = (a>>i) & 1
c = ((c << 1) | b) & 0xff
return c
# register definitions
SET_CONTRAST = const(0x81)
@ -100,6 +108,14 @@ class SSD1306(framebuf.FrameBuffer):
self.write_cmd(self.pages - 1)
self.write_data(self.buffer)
# rotates the framebuffer by 180°
def rotate180(self):
last = 1023
for i in range(0, 512):
x = invert(self.buffer[i])
self.buffer[i] = invert(self.buffer[last])
self.buffer[last] = x
last -= 1
class SSD1306_I2C(SSD1306):
def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):