From e5f488ae91a7d7862efad5762794206b701ea25c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 8 Apr 2021 15:06:44 +0200 Subject: add ssd1306 (I2C OLED display) examples --- commandline/examples/ssd1306-getpixels | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 commandline/examples/ssd1306-getpixels (limited to 'commandline/examples/ssd1306-getpixels') 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))) -- cgit v1.2.3