include the sensor switch

main
vitrinekast 6 months ago
parent 367f15e37c
commit e6d64256ce

@ -4,15 +4,19 @@ import numpy as np
import os
import random
import simpleaudio as sa
import threading
import time
import board
import busio
import adafruit_mpr121
MEDIA_FOLDER = "media"
WINDOW_NAME = "Image Viewer"
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 480
WINDOW_WIDTH = 300
WINDOW_HEIGHT = 500
i2c = busio.I2C(board.SCL, board.SDA)
mpr121 = adafruit_mpr121.MPR121(i2c)
mediaFolder = os.listdir(MEDIA_FOLDER)
current_file = False
@ -21,6 +25,9 @@ def clear_frame():
# Create a black frame
black_frame = np.zeros((WINDOW_HEIGHT, WINDOW_WIDTH, 3), dtype=np.uint8)
cv2.imshow(WINDOW_NAME, black_frame)
cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.waitKey(1) # Add a small delay to ensure the frame is displayed
@ -68,18 +75,15 @@ def showImage(file):
a = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
resized_frame = resize_and_center_frame(current_image)
cv2.imshow(WINDOW_NAME, resized_frame)
k = cv2.waitKey(0)
if k < 58 and k > 48:
print("number is pressed")
print(k - 48)
load_media(k - 48)
elif k == ord("q"):
print("destroy all windows")
cv2.destroyAllWindows()
else:
print("key pressed: " + str(k))
cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
while True:
for i in range(12):
if mpr121[i].value:
print("Pin {} touched!".format(i))
load_media(i)
break
def play_audio(file):
clear_frame()
@ -136,11 +140,13 @@ def load_media(region=None, override=None):
if ret == True:
cv2.imshow(WINDOW_NAME, resized_frame)
if cv2.waitKey(3) & 0xFF == ord("1"):
print("key 2 pressed")
load_media()
for i in range(12):
if mpr121[i].value:
print("Pin {} touched!".format(i))
load_media(i)
break
elif cv2.waitKey(3) & 0xFF == ord("q"):
if cv2.waitKey(3) & 0xFF == ord("q"):
print("destroy all windows")
cv2.destroyAllWindows()
break

Loading…
Cancel
Save