include the sensor switch

main
vitrinekast 6 months ago
parent 367f15e37c
commit e6d64256ce

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

Loading…
Cancel
Save