mimo / main2.py
main2.py
Raw
import pygame
from pygame.locals import *
import signal
from PIL import Image
import time
from mfrc522 import SimpleMFRC522
import RPi.GPIO as GPIO

GPIO.setwarnings(False)

# Initialize the RFID reader
reader = SimpleMFRC522()

# Initialise Pygame and the touchscreen display
pygame.init()
pygame.mouse.set_visible(False)
screen = pygame.display.set_mode((1025, 600))

# Load the images
image1 = pygame.image.load("Authentication drop off.png")
image2 = pygame.image.load("Authentication drop off2.png")
image3 = pygame.image.load("Authentication drop off3.png")
image4 = pygame.image.load("Authentication drop off4.png")

# Show image1 initially
current_image = image1

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            raise SystemExit

    # Read the RFID card
    id, text = reader.read_no_block()

    if id:
        print("RFID Tag ID:", id)
        print("RFID Tag Data:", text)
        # If the RFID card is authenticated, show image3  if text.strip() == "authenticated":
        if current_image == image2 and id == 526668169403:
            current_image = image3

    # Get the position of the touchscreen click
    pos = pygame.mouse.get_pos()

    # Check if the touchscreen is clicked
    if pygame.mouse.get_pressed()[0] == 1:
        # If image1 is clicked, show image2
        if current_image == image1:
            current_image = image2
        # If image3 is clicked, show image4
        elif current_image == image3:
            current_image = image4

    # Draw the current image on the screen
    screen.blit(current_image, (0, 0))
    pygame.display.update()