/***********************************************
** Chronomètre 1"30 pour pizza napolitaine **
** Afficheur TM1637 + 2 boutons Start / RAZ **
************************************************/
// Appel de la bibliothèque de l'afficheur
#include <TM1637Display.h>
// Attribution d'un nom explicite aux broches
#define pinBoutonRaz 4
#define pinBoutonStart 5
#define pinClk 2
#define pinDio 3
#define pinBuzzer 6
// Création de l'objet afficheur
TM1637Display afficheur(pinClk,pinDio);
// Définition du temps de cuisson
unsigned long tempsCuisson = 90000; // 90 secondes
unsigned long tempsStart = 0;
boolean isRunning = false; // Chrono en route
boolean activeBuzzer = true; // Buzzer actif
//##### Fonction pour convertir le temps ms en mn:ss
unsigned int nombreAfficheur(unsigned long temps = 0) {
unsigned minutes = int(temps / 60000);
unsigned secondes = int((temps-60000*minutes)/1000);
return 100*minutes + secondes;
}
void setup() {
// Déclaration des E/S
pinMode(pinBoutonRaz, INPUT_PULLUP);
pinMode(pinBoutonStart, INPUT_PULLUP);
pinMode(pinBuzzer, OUTPUT);
// Initialisation de l'afficheur
afficheur.setBrightness(4);
afficheur.showNumberDecEx(nombreAfficheur(tempsCuisson), 0b01000000, true);
// Initialisation liaison série
Serial.begin(115200);
Serial.println("Chronometre à pizzas !");
}
void loop() {
// Bouton RAZ : remise à zéro et stop buzzer
if(digitalRead(pinBoutonRaz)==LOW) {
Serial.println("Bouton RAZ");
isRunning = false;
activeBuzzer = true;
noTone(pinBuzzer);
afficheur.showNumberDecEx(nombreAfficheur(tempsCuisson), 0b01000000, true);
}
// Si chrono en route
if(isRunning) {
long duree = millis()-tempsStart;
if(duree%1000>=500){
afficheur.showNumberDecEx(nombreAfficheur(duree), 0b01000000, true);
}
else {
afficheur.showNumberDecEx(nombreAfficheur(duree), 0b00000000, true);
}
// Test durée et alarme
if((duree >= tempsCuisson) && (activeBuzzer == true)) {
if(duree%500 >= 250) {
tone(pinBuzzer, 4000);
}
else {
noTone(pinBuzzer);
}
// Si alarme et appui sur le bouton Start -> Stop alarme
if(digitalRead(pinBoutonStart)==LOW){
activeBuzzer = false;
noTone(pinBuzzer);
}
}
}
// Si chrono pas en route
else{
// Appui sur le bouton Start
if(digitalRead(pinBoutonStart)==LOW){
isRunning = true;
tempsStart = millis();
Serial.println("Bouton Start");
}
}
}
RAZ
Start