Skip to content

Added rotate180 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -100,6 +108,14 @@ def show(self):
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):
Expand Down