diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-04-08 15:06:44 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-04-08 15:06:44 +0200 |
commit | e5f488ae91a7d7862efad5762794206b701ea25c (patch) | |
tree | 429adb25462ac6011e446a1be550f898ffc91354 /commandline/examples/ssd1306-getpixels | |
parent | f777d3db298b99ecb28558bbc5f24494e825d328 (diff) |
add ssd1306 (I2C OLED display) examples
Diffstat (limited to 'commandline/examples/ssd1306-getpixels')
-rwxr-xr-x | commandline/examples/ssd1306-getpixels | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/commandline/examples/ssd1306-getpixels b/commandline/examples/ssd1306-getpixels new file mode 100755 index 0000000..8527b7a --- /dev/null +++ b/commandline/examples/ssd1306-getpixels @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from PIL import Image +import sys + +buf_w = 128 +buf_h = 64 + + +def load_image(filename): + im = Image.open(filename) + w, h = im.size + buf = [0 for i in range(buf_w * buf_h // 8)] + for y in range(min(h, buf_h)): + for x in range(min(w, buf_w)): + if im.getpixel((x, y)): + buf[(y // 8) * buf_w + x] |= 1 << (y % 8) + return buf + + +filename = sys.argv[1] +offset = int(sys.argv[2]) + +buf = load_image(filename) +buf = buf[offset : offset + 128] + +print(" ".join(map(str, buf))) |