Skip to content

Instantly share code, notes, and snippets.

@pixline
Last active November 17, 2020 22:23
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 pixline/9a3981cb934a8f5003bc171ae6ee56e9 to your computer and use it in GitHub Desktop.
Save pixline/9a3981cb934a8f5003bc171ae6ee56e9 to your computer and use it in GitHub Desktop.
Inky Impression test script (via pimoroni/inky and unsplash.com)
#!/usr/bin/env python3
import sys
from PIL import Image
from inky.inky_uc8159 import Inky, CLEAN
import urllib
import requests
from io import BytesIO
import time
import signal
import RPi.GPIO as GPIO
BUTTONS = [ 5, 6, 16, 24 ]
GPIO.setmode( GPIO.BCM )
GPIO.setup( BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP )
inky = Inky()
saturation = 0.3
def get_unsplash( geturl ):
response = requests.get( geturl )
image = Image.open( BytesIO( response.content ) )
inky.set_image(image, saturation=saturation)
inky.show()
def handle_button( pin ):
if pin == 5:
imgurl='https://source.unsplash.com/random/600x448?abstract'
elif pin == 6:
imgurl='https://source.unsplash.com/random/600x448?architecture'
elif pin == 16:
imgurl='https://source.unsplash.com/random/600x448?music'
elif pin == 24:
imgurl='https://source.unsplash.com/random/600x448?painting'
else:
imgurl='https://source.unsplash.com/random/600x448'
get_unsplash( imgurl )
for pin in BUTTONS:
GPIO.add_event_detect( pin, GPIO.FALLING, handle_button, bouncetime = 250 )
handle_button(0)
signal.pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment