Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2017 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/32b06b9d1d1804e3808b15b84d238c60 to your computer and use it in GitHub Desktop.
Save anonymous/32b06b9d1d1804e3808b15b84d238c60 to your computer and use it in GitHub Desktop.
disp = Adafruit_SSD1306.SSD1306_128_32(rst=0)
disp.begin()
FONT_PATH = '/usr/share/fonts/truetype/roboto/RobotoCondensed-Regular.ttf'
FONT = ImageFont.truetype(FONT_PATH, 22)
def display_data(t, h):
image = Image.new('1', (disp.width, disp.height))
draw = ImageDraw.Draw(image)
# Draw temperature / Humidity values.
draw.text((0, 8), '{0}°C'.format(t), font=FONT, fill=255)
draw.text((71, 8), '{0}%'.format(h), font=FONT, fill=255)
# Draw bar charts.
draw.rectangle((0, 0, 50, 8), outline=255, fill=0)
draw.rectangle((71, 0, 121, 8), outline=255, fill=0)
draw.rectangle((0, 0, t / 100.0 * 50, 8), outline=255, fill=255)
draw.rectangle((71, 0, 71 + (h / 100.0 * 50), 8), outline=255, fill=255)
# Send to OLED display.
disp.clear()
disp.image(image)
disp.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment