hello folks, i'm working on an accademic project with my custom Board based on the ATMEGA328p
16Mhz.
Some times my code stucks in the methods of ActionMethods.ino.
exactely in this loop
do
{
if(digitalRead(capTiroir1) && typeCaisse)break;// typeCaisse =0 then if(digitalRead(capTiroir1) && typeCaisse) will be always 0 so break will not be called
} while ((millis() - timestart) < 300) ; //we will be testing on the time out
i think the problem might be caused by millis overflow.
thankyou for your help.
My code:
main.ino
#define DEBUG // comment to desactivate debug
#define DEBLOCKING // comment to deactivate the deblocking functionality
//#define BLOCKING // comment to deactivate the blocking functionality
//#define configWithPot // comment to deactivate config temporisation with potentiometer
#define SonorisationTiroirOuvert // comment to deactivate the sonorisation when the drawer stays open for a time
#ifdef DEBUG
#include <ArduinoJson.h> // version 6.18.4
long lastSendTime;
#define sendDelay 1300
#endif
#include <EEPROM.h>
#define EI_ARDUINO_INTERRUPTED_PIN
#include <EnableInterrupt.h> // version 1.1.0
#include <SchedTask.h> // version 1.1.2
#define ConfigPin 6 // pin pour activé la configuration
#define timeOut 150 // timeout for ejection
#define indexT1EEprom 1
#define indexT2EEprom 3
#define indexT3EEprom 5
#define indexBlockCaisse 7 //indicate if blocked or not
#define indexBlockDelay 8 // the blocking delay
#define indexTypeCaisse 10 // the index of Type of the caisse in the eeprom
#define indexPasswordValidity 11 // indicats if the password is used or not
#define indexDeblockingPassword 12 // indicates the index of the first byte of the password
#define indexSonorisationTiroirOuvert 20// index to store the delay before checking if the drawer is opened is closed or not make a signale
unsigned long timestart;
//###################### Pins du clavier ####################
#define clavier1 7
#define clavier2 8
#define clavier3 9
#define potTempo A0 // pin pour le potentiomètre
#define LedR 12 // pin pour la LED Rouge
#define LedV 11 // pin pour la LED Verte
#define capTiroir1 A2 // capteur de fermeture pour le premier tiroir
#define capTiroir2 A3 // capteur de fermeture pour le deuxiéme tiroir
#define capTiroir3 A4 // capteur de fermeture pour le troisième tiroir
#define Tiroir1 A5 // pin d'activation moteur tiroir 1
#define Tiroir2 2 // pin d'activation moteur tiroir 2
#define Tiroir3 3 // pin d'activation moteur tiroir 3 //
#ifdef BLOCKING
#define pinBlock A1 // pin pour bloqué la caisse
#endif
#define buzzerPin 5 // pin pour buzzuer de
#define serrureSwitch 10 // switch présence clé
#define pinRelay 4
#define EI_ARDUINO_INTERRUPTED_PIN
#ifdef DEBUG
StaticJsonDocument<128> doc;
#endif
uint8_t bippingCount = 0; //value to indicate if the bipping in case of abscence of key and one of the drawers at least is already open
#define bippingTimes 50 // value of the bipping times
static unsigned long last_interrupt_time;
volatile byte lastPressedClavier = 0; //varible pour stocké la valeur du denier boutton présser
volatile bool config = false; // true mode config ,False mode noramle
unsigned long TempTiroir1, TempTiroir2, TempTiroir3; // variables des valeurs de temporisation pour chaque tiroir
volatile bool Tiroir1Trigred = false, Tiroir2Trigred = false, Tiroir3Trigred = false; // flags pour les etats des tiroir
volatile bool typeCaisse; // this value will indicate the type of the caise if 0 without drawer sensor if 1 with drawer sensor
//##################### signature des fonctions#######################
void initPins();
void UpdateTempValue(uint16_t potValue, byte addr);
uint16_t readValue(byte addr);
void clavierPress();
void activationTiroir1();
void activationTiroir2();
void activationTiroir3();
void serrureTogle();
void activateDrawerDeblockage();
void T1CheckCallback();
void T2CheckCallback();
void T3CheckCallback();
#ifdef BLOCKING
void blockCaisse();
void endBlockCaisse();
#endif
#ifdef DEBLOCKING
#define MAX_PASSWORD_LENGTH 6 // the max of the password
String PasswordEntred = ""; // the string to handle the entred password
SchedTask ejectTiroirDeblockage(NEVER, ONESHOT, activateDrawerDeblockage); // the task responsible for ejecting the drawers when the password matches
#endif
#ifdef SonorisationTiroirOuvert
bool T1SonorisationIndicator= false;
bool T2SonorisationIndicator= false;
bool T3SonorisationIndicator= false;
#endif
//############# fin signature des Fonctions #################
//############# difinition des taches planifier #######################
#ifdef SonorisationTiroirOuvert
SchedTask T1TempCheck(NEVER, ONESHOT, T1CheckCallback); // (NEXT,PERIODE,FUNCTION)
SchedTask T2TempCheck(NEVER, ONESHOT, T2CheckCallback);
SchedTask T3TempCheck(NEVER, ONESHOT, T3CheckCallback);
#endif
SchedTask ejectTiroir1Task(NEVER, ONESHOT, activationTiroir1); // (NEXT,PERIODE,FUNCTION)
SchedTask ejectTiroir2Task(NEVER, ONESHOT, activationTiroir2);
SchedTask ejectTiroir3Task(NEVER, ONESHOT, activationTiroir3);
//################### fin déclaration des taches planifier #######################
void setup()
{
#ifdef DEBUG
Serial.begin(250000);
lastSendTime = millis();
#endif
typeCaisse = readValue(indexTypeCaisse); // read the type of the caisse
initPins();
enableInterrupt(serrureSwitch, serrureTogle, FALLING);
enableInterrupt(clavier1, clavierPress, FALLING);
enableInterrupt(clavier2, clavierPress, FALLING);
enableInterrupt(clavier3, clavierPress, FALLING);
#ifdef BLOCKING
enableInterrupt(pinBlock, blockCaisse, FALLING); // interuption pour bloqué la caisse
#endif
last_interrupt_time = millis();
//#################### partie de configuration ############################
#ifdef configWithPot
while (!digitalRead(ConfigPin) & digitalRead(serrureSwitch))
{
#ifdef BLOCKING
EEPROM.put(indexBlockCaisse, false); // pour desactiver le déblockage
#endif
uint16_t potValue;
config = true;
switch (lastPressedClavier)
{
case 1:
lastPressedClavier = 0;
do
{
potValue = analogRead(potTempo);
} while (lastPressedClavier != 1);
UpdateTempValue(potValue, indexT1EEprom);
lastPressedClavier = 0;
break;
case 2:
lastPressedClavier = 0;
do
{
potValue = analogRead(potTempo);
} while (lastPressedClavier != 2);
UpdateTempValue(potValue, indexT2EEprom);
lastPressedClavier = 0;
break;
case 3:
lastPressedClavier = 0;
do
{
potValue = analogRead(potTempo);
} while (lastPressedClavier != 3);
UpdateTempValue(potValue, indexT3EEprom);
lastPressedClavier = 0;
break;
}
}
#endif
#ifdef BLOCKING
if (readValue(indexBlockCaisse))
blockCaisse(); //pour détecter si la caisse a été bloqué
#endif
//####################### récupération des valeurs de temprisation ############
TempTiroir1 = EEPROMReadInt(indexT1EEprom);
TempTiroir2 = EEPROMReadInt(indexT2EEprom);
TempTiroir3 = EEPROMReadInt(indexT3EEprom);
}
void loop()
{
SchedBase::dispatcher();
#ifdef DEBUG
if (Serial.available() > 0)
{
DeserializationError error = deserializeJson(doc, Serial);
if (!error)
{
handleRecievedData();
}
}
if (millis() - lastSendTime > sendDelay)
{
sendConfigData();
Serial.println("");
lastSendTime = millis();
}
#endif
if (((digitalRead(capTiroir1) || digitalRead(capTiroir2) || digitalRead(capTiroir3)) && !digitalRead(serrureSwitch)) && typeCaisse)
{
if (bippingCount < bippingTimes) //if the bipping didn't depassed the 255 bipping
{
Buzzer(100, 1);
bippingCount++;
}
}
}
ActionFunctions.ino this tab conatins the methods to activate motors
void activationTiroir1() // this method activate the first motor
{
if (Tiroir1Trigred && digitalRead(serrureSwitch))
{
timestart = millis();
digitalWrite(Tiroir1, 0);
digitalWrite(buzzerPin, 1);
do
{
if(digitalRead(capTiroir1) && typeCaisse)break;// typeCaisse =0 then if(digitalRead(capTiroir1) && typeCaisse) will be always 0 so break will not be called
} while ((millis() - timestart) < 300) ; //testing on the time out
digitalWrite(Tiroir1, 1);
digitalWrite(buzzerPin, 0);
Tiroir1Trigred = false;
delay(300);//wait before Testing
if (!digitalRead(capTiroir1) && typeCaisse) Buzzer(50, 10);
}
}
void activationTiroir2() // this method activate the second motor
{
if (Tiroir2Trigred && digitalRead(serrureSwitch))
{
timestart = millis();
digitalWrite(Tiroir2, 0); //activation verin
digitalWrite(buzzerPin, 1); // activation buzzer
do
{
if(digitalRead(capTiroir2) && typeCaisse)break;
} while ((millis() - timestart) < 400) ; // tantque le capteur n'est pas ouver et le time out n'est pas ateint
digitalWrite(Tiroir2, 1); // désactivation verin
digitalWrite(buzzerPin, 0); //désactivation BUZZER
Tiroir2Trigred = false;
delay(300);//wait before Testing
if (!digitalRead(capTiroir2) && typeCaisse) Buzzer(50, 10); // if the drawer is not activated make some sound
}
}
void activationTiroir3() // this method activate the third motor
{
if (Tiroir3Trigred && digitalRead(serrureSwitch))
{
timestart = millis();
digitalWrite(Tiroir3, 0);
digitalWrite(buzzerPin, 1);
do
{
if(digitalRead(capTiroir3) && typeCaisse)break;
} while ((millis() - timestart) < 500) ;
digitalWrite(Tiroir3, 1);
digitalWrite(buzzerPin, 0);
Tiroir3Trigred = false;
delay(300);//wait before testing
if (!digitalRead(capTiroir3) && typeCaisse) Buzzer(50, 10);
}
}
void Buzzer(int periode, int times) // activation du buzzer avec une faréquance
{
for (int i = 0; i < times; i++)
{
digitalWrite(buzzerPin, 1);
delay(periode);
digitalWrite(buzzerPin, 0);
delay(periode);
}
}
#ifdef DEBLOCKING
void activateDrawerDeblockage()// this method will be called by ejectTiroirDeblockage task to eject the drawer
{
timestart = millis();
digitalWrite(Tiroir1, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir1) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir1, 1);
digitalWrite(buzzerPin, 0);
delay(1000);
timestart = millis();
digitalWrite(Tiroir2, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir2) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir2, 1);
digitalWrite(buzzerPin, 0);
delay(1000);
timestart = millis();
digitalWrite(Tiroir3, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir3) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir3, 1);
digitalWrite(buzzerPin, 0);
}
#endif
#ifdef SonorisationTiroirOuvert
// this method is called by the Tiroir1TemporisationCheck task to check if the drawer is stil opened to start the buzzer
void T1CheckCallback()
{
if(digitalRead(capTiroir1))
{
T1SonorisationIndicator=true;
T1TempCheck.setNext(50);
if(!(T2SonorisationIndicator&T3SonorisationIndicator))
{
digitalWrite(buzzerPin, !digitalRead(buzzerPin));
}
}
else {
T1TempCheck.setNext(NEVER);
digitalWrite(buzzerPin, 0);
T1SonorisationIndicator=false;
}
}
void T2CheckCallback()
{
if(digitalRead(capTiroir2))
{
T2SonorisationIndicator=true;
T2TempCheck.setNext(50);
if(!(T1SonorisationIndicator&T3SonorisationIndicator))
{
digitalWrite(buzzerPin, !digitalRead(buzzerPin));
}
}
else {
T2TempCheck.setNext(NEVER);
digitalWrite(buzzerPin, 0);
T2SonorisationIndicator=false;
}
}
void T3CheckCallback()
{
if(digitalRead(capTiroir3))
{
T3SonorisationIndicator=false;
T3TempCheck.setNext(50);
if(!(T1SonorisationIndicator&T2SonorisationIndicator))
{
digitalWrite(buzzerPin, !digitalRead(buzzerPin));
}
}
else {
T3TempCheck.setNext(NEVER);
digitalWrite(buzzerPin, 0);
T3SonorisationIndicator=false;
}
}
#endif
DEBUG.ino
#ifdef DEBUG
void handleRecievedData() {
if (doc.containsKey("GC")) sendConfigData();
else if (doc.containsKey("SB")) setBlockTime();
else if (doc.containsKey("SDT")) setDrawerteporisation();
else if (doc.containsKey("AD")) ActivateDrawer();
else if (doc.containsKey("SCT")) SetCaisseType();
#ifdef DEBLOCKING
else if (doc.containsKey("SETPSWD")) changePassword();
else if (doc.containsKey("GETPSWD")) GetPassword();
#endif
#ifdef SonorisationTiroirOuvert
else if (doc.containsKey("SST")) setSenorisationTime();// set sonorisation time
#endif
}
void sendConfigData()// this method sen the config data to the board
{
doc.clear();
JsonArray DS = doc.createNestedArray("DS"); //drawerSensors
DS.add(digitalRead(capTiroir1));
DS.add(digitalRead(capTiroir2));
DS.add(digitalRead(capTiroir3));
JsonArray DT = doc.createNestedArray("DT");
DT.add(TempTiroir1);
DT.add(TempTiroir2);
DT.add(TempTiroir3);
doc["SS"] = digitalRead(serrureSwitch);
doc["BT"] = EEPROMReadInt(indexBlockDelay);
doc["SCT"] = typeCaisse;
serializeJson(doc, Serial);
}
void setBlockTime()// this function write the blocking time
{
EEPROMWriteInt(indexBlockDelay, doc["SB"].as<int>());
serializeJson(doc, Serial);
Buzzer(500, 1);
return;
}
void setDrawerteporisation()//write drawers temp values
{
JsonObject SDT = doc["SDT"];
if (SDT.containsKey("1")) {
EEPROMWriteInt(indexT1EEprom, SDT["1"].as<int>());
TempTiroir1 = EEPROMReadInt(indexT1EEprom);
doc.clear();
doc["SDT"] = 1;
serializeJson(doc, Serial);
Buzzer(500, 1);
return;
}
if (SDT.containsKey("2"))
{
EEPROMWriteInt(indexT2EEprom, SDT["2"].as<int>());
TempTiroir2 = EEPROMReadInt(indexT2EEprom);
doc.clear();
doc["SDT"] = 2;
serializeJson(doc, Serial);
Buzzer(500, 1);
return;
}
if (SDT.containsKey("3")) {
EEPROMWriteInt(indexT3EEprom, SDT["3"].as<int>());
TempTiroir3 = EEPROMReadInt(indexT3EEprom);
doc.clear();
doc["SDT"] = 3;
serializeJson(doc, Serial);
Buzzer(500, 1);
return;
}
}
void ActivateDrawer() {
int index = doc["AD"].as<int>();
switch (index) {
case 1 :
timestart = millis();
digitalWrite(Tiroir1, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir1) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir1, 1);
digitalWrite(buzzerPin, 0);
break;
case 2:
timestart = millis();
digitalWrite(Tiroir2, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir2) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir2, 1);
digitalWrite(buzzerPin, 0);
break;
case 3:
timestart = millis();
digitalWrite(Tiroir3, 0);
digitalWrite(buzzerPin, 1);
do
{
} while ((!digitalRead(capTiroir3) && typeCaisse) || (millis() - timestart) <= timeOut); //if typeCaisse=0 (!digitalRead(capTiroir1)&typeCaisse)will always 0 so we will be testing only on timeout
digitalWrite(Tiroir3, 1);
digitalWrite(buzzerPin, 0);
break;
}
serializeJson(doc, Serial);
return;
}
void SetCaisseType()// this function write the type of the caisse 0 without sensor, 1 with sensors
{
EEPROM.update(indexTypeCaisse, doc["SCT"].as<bool>());
serializeJson(doc, Serial);
typeCaisse = readValue(indexTypeCaisse);
Buzzer(500, 1);
return;
}
#ifdef DEBLOCKING
void changePassword()
{
char* password = doc["SETPSWD"];
writePassword(password);
EEPROM.update(indexPasswordValidity, true);// set the password validity indicator to true
}
void GetPassword(){
doc.clear();
JsonObject GETPSWD = doc.createNestedObject("GETPSWD");
GETPSWD["PSWD"] = readPassword();
GETPSWD["valid"] = readValue(indexPasswordValidity);
serializeJson(doc, Serial);
}
#endif
#endif
#ifdef SonorisationTiroirOuvert
void setSenorisationTime()// set sonorisation time
{
}
#endif
}
EEPROM.ino// this tab for writing/reading values in the EEprom
void UpdateTempValue(uint16_t potValue, byte addr)// écrire la valeur de temp
{
if(potValue<256)EEPROMWriteInt(addr, indexT1EEprom);
else if (potValue<512) EEPROMWriteInt(addr, indexT2EEprom);
else if(potValue<768)EEPROMWriteInt(addr, indexT3EEprom);
else EEPROMWriteInt(addr, 180);
}
uint16_t readValue(byte addr)// read a simple value
{
return EEPROM.read(addr);
}
void EEPROMWriteInt(int address, int value)// write long Value
{
byte two = (value & 0xFF);
byte one = ((value >> 8) & 0xFF);
EEPROM.update(address, two);
EEPROM.update(address + 1, one);
}
unsigned long EEPROMReadInt(int address)// read long value
{
long two = EEPROM.read(address);
long one = EEPROM.read(address + 1);
return ((two << 0) & 0xFFFFFF) + ((one << 8) & 0xFFFFFFFF);
}
#ifdef DEBLOCKING
String readPassword(){// this method read each bute of the password and make the string password and return it
char data[MAX_PASSWORD_LENGTH + 1];
for (int i = 0; i < MAX_PASSWORD_LENGTH; i++)
{
data[i] = EEPROM.read(indexDeblockingPassword + i);
}
data[MAX_PASSWORD_LENGTH] = '\0';
return String(data);
}
void writePassword(char* password)// this method split the password and save aeach character(byte) individually
{
for (int i = 0; i < MAX_PASSWORD_LENGTH; i++)
{
EEPROM.write(indexDeblockingPassword + i, password[i]);
}
}
#endif
INIT.ino// tab for initialising pins and timer
void initPins()
{
pinMode(Tiroir1,INPUT_PULLUP);
pinMode(Tiroir2,INPUT_PULLUP);
pinMode(Tiroir3,INPUT_PULLUP);
pinMode(Tiroir1,OUTPUT);
pinMode(Tiroir2,OUTPUT);
pinMode(Tiroir3,OUTPUT);
digitalWrite(Tiroir1,1);
digitalWrite(Tiroir1,1);
digitalWrite(Tiroir1,1);
pinMode(ConfigPin, INPUT_PULLUP);
pinMode(clavier1,INPUT_PULLUP);
pinMode(clavier2, INPUT_PULLUP);
pinMode(clavier3,INPUT_PULLUP);
pinMode(potTempo,INPUT);
pinMode(LedR, OUTPUT);
pinMode(LedV,OUTPUT);
pinMode(capTiroir1, INPUT_PULLUP);
pinMode(capTiroir2, INPUT_PULLUP);
pinMode(capTiroir3, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
pinMode(serrureSwitch,INPUT_PULLUP);
pinMode(pinRelay,OUTPUT);
setupTimer();
#ifdef BLOCKNG
pinMode(pinBlock, INPUT_PULLUP);
#endif
}
void setupTimer()
{
cli();
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();
}
Interruption.ino// tabs for methods that hundeling interruptions
void clavierPress() {
if ((millis() - last_interrupt_time) > 400) {
last_interrupt_time = millis();
if (digitalRead(serrureSwitch)) {// the key is present
if (config) {
switch (arduinoInterruptedPin) {
case clavier1:
lastPressedClavier = 1;
break;
case clavier2:
lastPressedClavier = 2;
break;
case clavier3:
lastPressedClavier = 3;
break;
}
} else {
digitalWrite(LedV, 0);
switch (arduinoInterruptedPin) {
case clavier1:
if ((!Tiroir1Trigred && !digitalRead(capTiroir1)&& typeCaisse)||(!Tiroir1Trigred && !typeCaisse))
{
ejectTiroir1Task.setNext(TempTiroir1*1000);
Tiroir1Trigred = true;
#ifdef SonorisationTiroirOuvert
T1TempCheck.setNext(5000);
#endif
}
break;
case clavier2:
if ((!Tiroir2Trigred && !digitalRead(capTiroir2)&& typeCaisse)||(!Tiroir2Trigred && !typeCaisse)) {
ejectTiroir2Task.setNext(1000 * TempTiroir2);
Tiroir2Trigred = true;
#ifdef SonorisationTiroirOuvert
T2TempCheck.setNext(5000);
#endif
}
break;
case clavier3:
if ((!Tiroir3Trigred && !digitalRead(capTiroir3)&& typeCaisse)||(!Tiroir3Trigred && !typeCaisse)) {
ejectTiroir3Task.setNext(1000*TempTiroir3);
Tiroir3Trigred = true;
#ifdef SonorisationTiroirOuvert
T3TempCheck.setNext(5000);
#endif
}
break;
}
#ifdef DEBUG
doc.clear();
switch (arduinoInterruptedPin) {
case clavier1:
doc["keypad"] = 1;
break;
case clavier2:
doc["keypad"] = 2;
break;
case clavier3:
doc["keypad"] = 3;
break;
}
serializeJson(doc, Serial);
#endif
}
}
#ifdef DEBLOCKING
// if the case key is not present we will handle the password
else if (readValue(indexPasswordValidity))// testing if the password is used or not
{
switch (arduinoInterruptedPin) {// append the pressed key to the password String
case clavier1:
PasswordEntred+='1';
break;
case clavier2:
PasswordEntred+='2';
break;
case clavier3:
PasswordEntred+='3';
break;
}
// make al little bip for better user experience
digitalWrite(buzzerPin, 1);
delay(250);
digitalWrite(buzzerPin, 0);
if(PasswordEntred.length()==6)
{
if(PasswordEntred==readPassword()){// the password matches
ejectTiroirDeblockage.setNext(1000);//we schedule the drawers to be ejected after 1 second
EEPROM.update(indexPasswordValidity, false); // set the password indicator to false
PasswordEntred="";
}
else
{
PasswordEntred="";
}
}
}
#endif
return;
}
}
void serrureTogle() // fonction pour changer l'état si la clé est insérée ou retirée
{
if ((millis() - last_interrupt_time) > 200) {
last_interrupt_time = millis();
Tiroir1Trigred = false;
Tiroir2Trigred = false;
Tiroir3Trigred = false;
bippingCount = 0;// reset the bipping counts
T1TempCheck.setNext(NEVER);
T2TempCheck.setNext(NEVER);
T3TempCheck.setNext(NEVER);
digitalWrite(buzzerPin, 0);
}
return;
}
ISR(TIMER1_COMPA_vect) {
if (!(Tiroir1Trigred || Tiroir2Trigred || Tiroir3Trigred)) {
if (digitalRead(serrureSwitch)) {
digitalWrite(LedV, !digitalRead(LedV));
digitalWrite(LedR, 1);
} else {
digitalWrite(LedR, !digitalRead(LedR));
digitalWrite(LedV, 1);
}
}
}
#ifdef BLOCKING
void blockCaisse()// method for blocking time
{
if ((millis() - last_interrupt_time) > 200) {
last_interrupt_time = millis();
blockCaisseTask.setNext(EEPROMReadInt(indexBlockDelay) * 1000);
digitalWrite(pinRelay,HIGH);
EEPROM.put(indexBlockCaisse, true);
disableInterrupt(clavier1);
disableInterrupt(clavier2);
disableInterrupt(clavier3);
disableInterrupt(serrureSwitch);
Tiroir1Trigred = false;
Tiroir2Trigred = false;
Tiroir3Trigred = false;
}
return;
}
void endBlockCaisse()
{
EEPROM.put(indexBlockCaisse, false);
digitalWrite(pinRelay,LOW);
enableInterrupt(serrureSwitch, serrureTogle, CHANGE);
enableInterrupt(clavier1, clavierPress, FALLING);
enableInterrupt(clavier2, clavierPress, FALLING);
enableInterrupt(clavier3, clavierPress, FALLING);
Buzzer(50, 5);
return;
}
#endif