j’ai juste modifie l’incrémentation et il manquait un « . » avant un jpg et un autre truc mais sinon niquel
voila ce que j’ai pour l’instant, avec mon probleme de photo qui s’affiche qu’une demi sec:
[code]#!/usr/bin/env python2.7
-- coding: utf-8 -
import RPi.GPIO as GPIO
import time
from datetime import datetime
from PIL import Image
import pygame
from pygame.locals import *
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
PHOTOS = « /home/pi/Desktop/photos »
APP_RESSOURCES = « /home/pi/Desktop/ressources »
imageName_accueil = « %s/accueil.jpg » %APP_RESSOURCES
imageName_compteur_3 = « %s/compteur3.jpg » % APP_RESSOURCES
imageName_compteur_2 = « %s/compteur2.jpg » % APP_RESSOURCES
imageName_compteur_1 = « %s/compteur1.jpg » % APP_RESSOURCES
imageName_souriez = « %s/souriez.jpg » % APP_RESSOURCES
pygame.init()
screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
width, height = screen.get_size()
def takepic(imageName): #prend une photo (note: il faut selectionner la ligne qui correspond à votre installation en enlevant le premier # )
command = « sudo raspistill -t 1000 -w 960 -h 720 -o « + imageName + » -q 80 » #prend une photo
# command = « sudo raspistill -t 1000 -w 960 -h 720 -o « + imageName + » -rot 90 -q 80 » #prend une photo et la tourne de 90°
# command = « sudo raspistill -t 1000 -w 960 -h 720 -o « + imageName + » -rot 180 -q 80 » #prend une photo et la tourne de 180°
# command = « sudo raspistill -t 1000 -w 960 -h 720 -o « + imageName + » -rot 270 -q 80 » #prend une photo et la tourne de 270°
os.system(command)
def loadpic(imageName): # affiche imagename
print("loading image: " + imageName)
background = pygame.image.load(imageName);
background.convert_alpha()
background = pygame.transform.scale(background,(width,height))
screen.blit(background,(0,0),(0,0,width,height))
pygame.display.flip()
def minuterie():
#writemessage(" 3")
loadpic(imageName_compteur_3)
time.sleep(1)
#writemessage(" 2")
loadpic(imageName_compteur_2)
time.sleep(1)
#writemessage(" 1")
loadpic(imageName_compteur_1)
time.sleep(1)
#writemessage(« souriez »)
loadpic(imageName_souriez)
def writemessage(message): # pour pouvoir afficher des messages sur un font noir
screen.fill(pygame.Color(0,0,0))
font = pygame.font.SysFont(« verdana », 250, bold=1)
textsurface = font.render(message, 1, pygame.Color(255,255,255))
screen.blit(textsurface,(35,40))
pygame.display.update()
def writemessagetransparent(message): # pour pouvoir afficher des messages en conservant le font
font = pygame.font.SysFont(« verdana », 50, bold=1)
textsurface = font.render(message, 1, pygame.Color(255,255,255))
screen.blit(textsurface,(35,40))
pygame.display.update()
if name == ‹ main ›:
if (os.path.isdir(PHOTOS) == False): # si le dossier pour stocker les photos n’existe pas
os.mkdir(PHOTOS) # alors on crée le dossier (sur le bureau)
os.chmod(PHOTOS,0o777) # et on change les droits pour pouvoir effacer des photos
while True : #boucle jusqu’a interruption
try:
loadpic(imageName_accueil)
#on attend que le bouton soit pressé
GPIO.wait_for_edge(18, GPIO.FALLING)
# on a appuyé sur le bouton...
#on lance le decompte
minuterie()
#on genere le nom de la photo avec heure_min_sec
date_today = datetime.now()
nom_image = date_today.strftime('%d_%m_%H_%M_%S')
#on prend la photo
chemin_photo = "%s/%s.jpeg" % (PHOTOS,nom_image)
takepic(chemin_photo) #on prend la photo
#on affiche la photo
loadpic(chemin_photo)
if (GPIO.input(18) == 0): #si le bouton est encore enfoncé (sont etat sera 0)
print("bouton appuye, je dois repartir au début de ma boucle")
continue # alors on sort du while
except KeyboardInterrupt:
print ‹ sortie du programme! ›
raise
GPIO.cleanup() # reinitialisation GPIO lors d’une sortie normale[/code]