Created
September 10, 2017 12:29
-
-
Save anonymous/32b06b9d1d1804e3808b15b84d238c60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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