Alors pour refaire un bilan de l’ensemble. Voila le programme complet après modification :
# before import the max6675, you must save the max6675.py file at "/usr/lib/python2.7/dist-packages"
# wiring
# Raspberry MAX6675
# GND ------ GND
# 5V ------ VCC
# pin 18 ------ SCK
# pin 22 ------ CS
# pin 16 ------ SO
import random, sys, time, pygame, datetime, max6675
from pygame.locals import *
# set the pin for communicate with MAX6675
cs = 22
sck = 18
so = 16
# max6675.set_pin(CS, SCK, SO, unit) [unit : 0 - raw, 1 - Celsius, 2 - Fahrenheit]
max6675.set_pin(cs, sck, so, 1)
FPS = 30
WINDOWWIDTH = 1280
WINDOWHEIGHT = 960
FLASHSPEED = 500 # in milliseconds
FLASHDELAY = 200 # in milliseconds
BUTTONSIZE = 200
BUTTONGAPSIZE = 20
TIMEOUT = 4 # seconds before game over if no button is pushed.
# R G B
WHITE = (255, 255, 255)
BLACK = ( 0, 0, 0)
BRIGHTRED = (255, 0, 0)
RED = (155, 0, 0)
BRIGHTGREEN = ( 0, 255, 0)
GREEN = ( 0, 155, 0)
BRIGHTBLUE = ( 0, 0, 255)
BLUE = ( 0, 0, 155)
BRIGHTYELLOW = (255, 255, 0)
YELLOW = (155, 155, 0)
DARKGRAY = ( 40, 40, 40)
bgColor = BLACK
XMARGIN = int((WINDOWWIDTH - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
YMARGIN = int((WINDOWHEIGHT - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
# Rect objects for each of the four buttons
YELLOWRECT = pygame.Rect(XMARGIN, YMARGIN, BUTTONSIZE, BUTTONSIZE)
BLUERECT = pygame.Rect(XMARGIN + BUTTONSIZE + BUTTONGAPSIZE, YMARGIN, BUTTONSIZE, BUTTONSIZE)
REDRECT = pygame.Rect(XMARGIN, YMARGIN + BUTTONSIZE + BUTTONGAPSIZE, BUTTONSIZE, BUTTONSIZE)
GREENRECT = pygame.Rect(XMARGIN + BUTTONSIZE + BUTTONGAPSIZE, YMARGIN + BUTTONSIZE + BUTTONGAPSIZE, BUTTONSIZE, BUTTONSIZE)
score = 0
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT, BEEP1, BEEP2, BEEP3, BEEP4
def terminate():
pygame.quit()
sys.exit()
def checkForQuit():
for event in pygame.event.get(QUIT): # get all the QUIT events
terminate() # terminate if any QUIT events are present
for event in pygame.event.get(KEYUP): # get all the KEYUP events
if event.key == K_ESCAPE:
terminate() # terminate if the KEYUP event was for the Esc key
#pygame.event.post(event) # put the other KEYUP event objects back
pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('Contrôle du four!')
BASICFONT = pygame.font.Font('freesansbold.ttf', 16)
BASICFONT2 = pygame.font.Font('freesansbold.ttf', 32)
BASICFONT3 = pygame.font.Font('freesansbold.ttf', 64)
BASICFONT4 = pygame.font.Font('freesansbold.ttf', 96)
infoSurf = BASICFONT.render('DV GROUP V1.0', 1, YELLOW)
infoRect = infoSurf.get_rect()
infoRect.topleft = (10, WINDOWHEIGHT - 25)
date1 = 0
tempconsigne = 27
tempmem = 0
tempmem2 = 0
date = 0
date2 = 0
date3 = 0
date4 = 0
date5 = 0
instant = 0
instant2 = "Attente"
datedepart = datetime.datetime.now()
instant1 = (str(datedepart.hour) + ':' + str(datedepart.minute)+ ':' + str(datedepart.second))
while True: # main game loop
# read temperature connected at CS 22
a = max6675.read_temp(cs)
date = datetime.datetime.now()
instant = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
if (a >= tempconsigne) and (tempmem == 0):
tempmem =1
date1 = datetime.datetime.now()
instant2 = (str(date1.hour) + ':' + str(date1.minute)+ ':' + str(date1.second))
if (a >= tempconsigne) and (tempmem == 1):
date2 = date1-date
#instant2 = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second))
if (a <= 26) and (tempmem == 1):
tempmem =1
date1 = datetime.datetime.now()
instant2 = (str(date1.hour) + ':' + str(date1.minute)+ ':' + str(date1.second))
if (a <= 26) and (tempmem == 1):
date2 = date-date1
#instant2 = (str(date.hour) + ':' + str(date.minute)+ ':' + str(date.second)-1)
DISPLAYSURF.fill(bgColor)
DISPLAYSURF.blit(infoSurf, infoRect)
#affichage heure
scoreSurf = BASICFONT.render('' + str(instant), 1, WHITE)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (WINDOWWIDTH - 100, WINDOWHEIGHT - 25)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affichage heure demarrage
scoreSurf = BASICFONT2.render('Heure de départ:' + str(instant1), 1, YELLOW)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (10, 0)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affichage heure temp atteind
scoreSurf = BASICFONT2.render('Heure temp ok:' + str(instant2), 1, YELLOW)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (10, 30)
DISPLAYSURF.blit(scoreSurf, scoreRect)
#affiche text temps etuvage
scoreSurf1 = BASICFONT2.render('Temps d étuvage: ', 1, RED)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 60)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche compteur temps etuvage
scoreSurf1 = BASICFONT3.render(str(date2), 1, RED)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 85)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche text temperature four
scoreSurf1 = BASICFONT2.render('Température Four', 1, BLUE)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 150)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche temperature four
scoreSurf1 = BASICFONT3.render(str(round(a,0)) + '°C', 1, BLUE)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 180)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche consigne temperature
scoreSurf1 = BASICFONT2.render('Consigne de température', 1, GREEN)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 245)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
#affiche temperature de consigne
scoreSurf1 = BASICFONT3.render(str(round(tempconsigne,0)) + '°C', 1, GREEN)
scoreRect1 = scoreSurf1.get_rect()
scoreRect1.topleft = (10, 280)
DISPLAYSURF.blit(scoreSurf1, scoreRect1)
checkForQuit()
#max6675.time.sleep(2)
pygame.display.update()
pygame.time.wait(1000)
J’ai ensuite lancé le programme, je vais décrire celui-ci du mieux que je peux :
dans un premier temps --> RUN MODULE
- Consigne de température à 27°C et température ambiante 24°C : chronomètre affiche 0
- Je monte donc en température pour dépasser le seuil de 27°C
- Température à 28°C : chronomètre affiche 24 : 00 : 00 puis décompte
- la température redescend à 26°C : chronomètre affiche et bloque à 23 : 58 : 46
- Au bout d’une dizaine de seconde sans remonter la température le chronomètre se rénitialise et affiche 23 : 59 : 59
Donc si on remonte en température, le chronomètre recommencera à décompter, et ainsi de suite.
Ce que je ne comprend pas c’est pourquoi ce n’est plus un chrono mais un minuteur ?