I am trying to make a program that displays a still image(IM1) on a screen all the time, then when a gpio port(Relay 1) is brought to ground have a new image(IM2) pop up and alternate between IM2 and its counterpart(IM3). Here is my code as of now:
import RPi.GPIO as GPIO
import pygame
from pygame.locals import *
clock = pygame.time.Clock()
pygame.init()
clock.tick(60)
screen = pygame.display.set_mode((1080, 1920))
IM1 = pygame.image.load("/home/pi/Desktop/Slides/Logo.jpg")
IM2 = pygame.image.load("/home/pi/Desktop/Slides/Works-1.jpg")
IM3 = pygame.image.load("/home/pi/Desktop/Slides/Works-2.jpg")
GPIO.setmode(GPIO.BOARD)
Relay1 = 11
GPIO.setup(Relay1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while(1):
if(GPIO.input(Relay1) == 0):
screen.blit(IM2, (0,0))
sleep(.5)
screen.blit(IM3, (0,0))
sleep(.5)
pygame.display.update()
else:
screen.blit(IM1, (0,0))
pygame.display.update()
#I can get IM1 to function but when Relay 1 is triggered only IM3 is displayed. I have tried using sprite and cant get that to work i was hoping to get this method to work.