Skip to content

Instantly share code, notes, and snippets.

@henrikh
Created May 28, 2015 07:03
Show Gist options
  • Save henrikh/c6c208c3de600c10974b to your computer and use it in GitHub Desktop.
Save henrikh/c6c208c3de600c10974b to your computer and use it in GitHub Desktop.
# Configuration file
DISPLAY_TIME = 50
entries = [
{
"src": "1829.jpg",
"xy": (0, 384),
"key": "1",
"pin": 23
},
{
"src": "1846.jpg",
"xy": (0, 0),
"key": "2",
"pin": 23
},
{
"src": "1857.jpg",
"xy": (340, 384),
"key": "3",
"pin": 23
},
{
"src": "1877.jpg",
"xy": (360, 0),
"key": "4",
"pin": 23
},
{
"src": "1890.jpg",
"xy": (342 + 340, 384),
"key": "5",
"pin": 23
},
{
"src": "1895.jpg",
"xy": (342 + 360, 0),
"key": "6",
"pin": 23
}
]
# -*- coding: utf-8 -*-
import time, pygame, sys
from pygame.locals import *
import RPi.GPIO as GPIO
from time import sleep
from config import entries
from config import DISPLAY_TIME
pygame.init() #initierer python
clock = pygame.time.Clock()
GPIO.setmode(GPIO.BCM) #opsætning af GPIO
size = width, height, = 1024,768 #definition af vinduets størrelse
black = 0, 0, 0 #definition af hvid farve
screen = pygame.display.set_mode(size) #oprettelse af vindue
baggrund = pygame.image.load("asset/bg.jpg") #Load af billede
assets = {}
asset_active = {}
for entry in entries:
assets[entry["src"]] = pygame.image.load("asset/" + entry["src"])
asset_active[entry["src"]] = [0, entry]
#GPIO.setup(entry["pin"], GPIO.IN)
y = 0 #udgangspunkt for animation af tekstfiler
# Fullscreen/Windows state machine
WINDOW = 0
FULLSCREEN = 1
WINDOW_STATE = WINDOW
while True:
try:
clock.tick(10)
screen.fill(black)
screen.blit(baggrund, (0, 0))
for key in asset_active.keys():
if asset_active[key][0] > 0:
screen.blit(assets[key], asset_active[key][1]["xy"])
asset_active[key][0] -= 1
for entry in entries:
if GPIO.input(entry["pin"]) == False:
asset_active[entry["src"]][0] = DISPLAY_TIME
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if pygame.key.name(event.key) == "f":
if WINDOW_STATE == WINDOW:
pygame.display.set_mode(size, pygame.FULLSCREEN)
WINDOW_STATE = FULLSCREEN
else:
pygame.display.set_mode(size, pygame.RESIZABLE)
WINDOW_STATE = WINDOW
if pygame.key.name(event.key) == "q":
exit()
for entry in entries:
if pygame.key.name(event.key) == entry["key"]:
asset_active[entry["src"]][0] = DISPLAY_TIME
except KeyboardInterrupt:
exit()
pygame.display.flip() #tegner billedet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment