En préparatif de mariage, je désire faire un photobooth qui fera les choses suivante:
- bouton poussoir allumer prêt pour fonctionner
- une fois le bouton poussoir actionner éteindre le bon ton et faire un décompte sur une LED orange
- prise e la photo
Affichage de la photo
Fin de la boucle
Par contre, je rencontre des problèmes dans mon programme : au niveau de la boucle l'image ready s'affiche par intermittence et le bouton switch n'est pas réactif comme si il fallait l'actionner au bon moment. Je pense que cela provient de la structure le la boucle mais si je fait l'Indentation du if gpio switch au même endroit que le if pygame cela ne fonctionne pas. Pouvez vous m'aider svp ? Mer par avance
Code : Tout sélectionner
#!/usr/bin/python
import RPi.GPIO as GPIO, time, os, subprocess
import pygame , sys
from pygame.locals import *
import atexit
import socket
import threading
import os
from time import sleep, strftime
#variables
transform_x = 1280
transform_y = 768
offset_x = 0
offset_y = 0
real_path = os.path.dirname(os.path.realpath('_file_'))
photo_dir = real_path
# GPIO setup
GPIO.setmode(GPIO.BCM)
SWITCH = 24
GPIO.setup(SWITCH, GPIO.IN)
RESET = 25
GPIO.setup(RESET, GPIO.IN)
PRINT_LED = 22
POSE_LED = 18
BUTTON_LED = 23
GPIO.setup(POSE_LED, GPIO.OUT)
GPIO.setup(BUTTON_LED, GPIO.OUT)
GPIO.setup(PRINT_LED, GPIO.OUT)
GPIO.output(BUTTON_LED, True)
GPIO.output(PRINT_LED, False)
#fonctions
def init_pygame():
pygame.init()
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
pygame.display.set_caption('Photo Booth Pics')
return pygame.display.set_mode (size, pygame.FULLSCREEN)
def show_image(image_path):
screen = init_pygame()
img = pygame.image.load(image_path)
img = pygame.transform.scale(img,(transform_x,transform_y))
screen.blit(img, (offset_x, offset_y))
pygame.display.flip()
def capture():
#Allumer LED ORANGE et decompte
#snap value it 1 2 3 or 4 depending the number of snapshot
show_image(real_path + '/scripts/photoboothelo/image/pose.jpg')
GPIO.output(BUTTON_LED, False)
GPIO.output(POSE_LED, True)
time.sleep(1.5)
for i in range(5):
GPIO.output(POSE_LED, False)
time.sleep(0.4)
GPIO.output(POSE_LED, True)
time.sleep(0.4)
for i in range(5):
GPIO.output(POSE_LED, False)
time.sleep(0.1)
for i in range(5):
GPIO.output(POSE_LED, False)
time.sleep(0.1)
GPIO.output(POSE_LED, True)
time.sleep(0.1)
GPIO.output(POSE_LED, False)
print("SNAP")
now = strftime('%Y-%m-%d_%H:%M:%S')
last_picture = '/home/pi/photobooth_images/photo' + now + '.jpg'
show_image(real_path + '/scripts/photoboothelo/image/snap.jpg')
print("filename:" + last_picture)
gpout = subprocess.check_output("gphoto2 --capture-image-and-download --filename " + last_picture + " --force-overwrite", stderr=subprocess.STDOUT, shell=True)
print(gpout)
GPIO.output(POSE_LED, False)
show_image(last_picture)
time.sleep(5)
#Allumer LED VERTE
time.sleep(0.5)
GPIO.output(PRINT_LED, True)
#Recommence un cycle
time.sleep(1)
print("ready for next round")
GPIO.output(PRINT_LED, False)
GPIO.output(BUTTON_LED, True)
show_image(real_path + '/scripts/photoboothelo/image/next.jpg')
pygame.init()
screen=pygame.display.set_mode((transform_x,transform_y))
continuer = True
#Programme principal#
while continuer:
show_image(real_path + '/scripts/photoboothelo/image/ready.png')
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("quit")
pygame.quit()
sys.exit()
continuer = False
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
if (GPIO.input(SWITCH)):
print("pose!")
capture()
continuer = True
# while snap < 1:
# continuer = 1
# snap +=1
pygame.event.clear()
time.sleep(1)