Bonjour,
Je souhaiterais demander de l'aide pour quelques parties de code. Étant novice, je n'arrive pas à créer une fonction avec deux boutons poussoirs. Voici mon code.
Merci
#include <Wire.h>
#include <Keypad.h>
#include <Keypad_I2C.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#include "RedMP3.h"
#include <MFRC522.h>
#include <SPI.h>
#include <TM1637Display.h>
#include <I2C_eeprom.h> // https://github.com/RobTillaart/I2C_EEPROM
#define blazerwood // A mettre en remarque si jpbbricole
//------------------------------------- digital display
#define CLK 41
#define DIO 40
TM1637Display display = TM1637Display(CLK, DIO);
//------------------------------------- Début du jeux
#define BUTTON_PIN 22
#define DEBOUNCE_DELAY 50 // délai de rebond pour le bouton en millisecondes
// Define the RX and TX pins to establish UART communication with the MP3 Player Module.
#define MP3_RX 19//RX of Serial MP3 module connect to D4 of Arduino
#define MP3_TX 18//TX to D2, note that D2 can not be used as RX on Mega2560, you should modify this if you donot use Arduino UNO
MP3 mp3(MP3_RX, MP3_TX);
int8_t volume = 0x0d;//0~0x1e (30 adjustable level)
int8_t folderName = 0x01;//folder name must be 01 02 03 04 ...
int8_t fileName = 0x01; // prefix of file name must be 001xxx 002xxx 003xxx 004xxx ...
//------------------------------------- RFID
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
//------------------------------------- Clavier
#ifdef blazerwood
const int keybI2cAddress = 0x25;
#else // jpbbricole
const int keybI2cAddress = 0x38;
#endif
const byte keybRowsNbr = 4;
const byte keybColsNbr = 4;
//--------------------------------------------------------------------------------------------------BIP MINUTEUR
unsigned long previousTime = millis(); // Enregistrer le temps actuel
unsigned long delayDuration = 1000; // Durée du délai en millisecondes
unsigned long dureeMinuteur = 0; // Durée initiale du minuteur en millisecondes
//------------------------------------- Désamorçage (desam)
const String desalFctLabel[] = {"Desamorcage", "Explosion", "Temps demi", "Temps cache", "OFF"};
enum {desamFctDesamorcage, desamFctExplosion, desamFctTempsDemi, desamFctTempsCache, desamFctOff};
int desamFonction = desamFctOff;
#ifdef blazerwood
const int desamPin[] = {2, 3, A0, A1};
const int desamEtatOn = HIGH; // Etat quand fil interrompu
#else // jpbbricole
const int desamPin[] = {2, 3, A0, A1};
const int desamEtatOn = LOW; // Etat quand fil interrompu
#endif
const int desamFctNombre = sizeof(desamPin) / sizeof(desamPin[0]);
int desamFct = desamFctOff; //Fonction de desamorçage en cours
//------------------------------------- Tableau de nombre au hasard
struct rndArrayDef {boolean sorti = false; int nombre = 0;};
rndArrayDef rndArray[desamFctNombre];
boolean rndArrayInTest = false; // Pour faciliter les test, sort toujours un tableau contenant 0, 1, 2, 3...
//------------------------------------- Temps, pour accélérer les delay()
#ifdef blazerwood
const int timeFactor = 1;
#else // jpbbricole
const int timeFactor = 5;
#endif
const char keysMape[keybRowsNbr][keybColsNbr] =
{
#ifdef blazerwood
{'D', 'C', 'B', 'A'},
{'#', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
#else
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
#endif
};
#ifdef blazerwood
const byte keybRowPins[keybRowsNbr] = {3, 2, 1, 0};
const byte keybColPins[keybColsNbr] = {7, 6, 5, 4};
#else
const byte keybRowPins[keybRowsNbr] = {7, 6, 5, 4}; // Connexion des lignes
const byte keybColPins[keybColsNbr] = {3, 2, 1, 0}; // Connexion des colonnes
#endif
Keypad_I2C customKeypad(makeKeymap(keysMape), keybRowPins, keybColPins, keybRowsNbr, keybColsNbr, keybI2cAddress);
//------------------------------------- Affichages LCD
#ifdef blazerwood
const int lcdAadresse = 0x26; // Adresse du premier écran
const int lcdBadresse = 0x27; // Adresse du second écran
#else
const int lcdAadresse = 0x26; // Adresse du premier écran
const int lcdBadresse = 0x3F; // Adresse du second écran
#endif
LiquidCrystal_I2C lcdA(lcdAadresse, 20, 4);
LiquidCrystal_I2C lcdB(lcdBadresse, 20, 4);
byte lcdGlitchSnow[8] = // Pour afficher la neige sur les écrans
{
0b00000, 0b00000, 0b01110, 0b11111,
0b11111, 0b01110, 0b00000, 0b00000,
};
byte lcdGlitchSnowLittle[8] =
{
0b00000, 0b00000, 0b00100, 0b01110,
0b01110, 0b00100, 0b00000, 0b00000,
};
int lcdGlitchLoop = 0; // Compteur de séquences du glitch
boolean lcdGlitchOn = false; // Glitch pas actif
const String gameModes[5] = {
"Search & destroy",
"Matchs a Mort",
"Dominations",
"Piratage",
"Decryptage",
};
//------------------------------------- LED
enum {ledColorGreen, ledColorYellow, ledColorRed};
const int ledColorIndex[] = {5, 6, 7};
const int ledNumber = sizeof(ledColorIndex) / sizeof(ledColorIndex[0]);
const int ledOn = HIGH;
//------------------------------------- Servo
const int servoPin = 8;
Servo myServo;
//------------------------------------- Etats du jeu
enum { jeuEtatDemarrage, jeuEtatSelMode, jeuEtatSelTime, jeuEtatSelCode, jeuEtatEnCours, jeuEtatBombeBoom, jeuEtatBombeToOff, jeuEtatAttNfc, jeuEtatFin, jeuEtatArrete};
const String jeuEtatLabel [] = {"Demarrage", "Select mode", "Select time", "Select code", "En cours", "Bombe BOOM", "Bombe desamorcee", "Att. NFC", "Fin", "Arrete"};
int jeuEtat;
int selectedMode;
int selectedTime;
//------------------------------------- Tableau des UID et pseudo
const int uidNombre = 20;
const int uidSize = 9;
const int uidNomSize = 10;
struct uidMemDef // Structure de données des UID pour mémoire EEPRROM
{
char uid[uidSize];
char nom[uidNomSize];
};
uidMemDef uidMem;
const int uidRecordSize = sizeof(uidMem);
struct uidWorkDef // Structure de données des UID pour travail
{
String uid;
String nom;
};
uidWorkDef uidWork;
//------------------------------------- EEPROM
I2C_eeprom eeprom24C(0x50, I2C_DEVICESIZE_24LC256);
const word eeprCheckWord = 0xCAFE; // Pour repérer si c'est un premier usage
const int eeprOffsetCheckWord = 0; // Adresse du début de la mémoire
const int eeprOffsetUid = eeprOffsetCheckWord + sizeof(eeprCheckWord); // Adresse du début de la mémoire des UID
//------------------------------------- Divers
unsigned long timerDuration;
unsigned long startTime;
bool bombExploded = false;
bool alreadyExploded = false;
String disarmCode; // Variable pour stocker le code de désarmement
int disarmCodeLength = 4; // Longueur par défaut du code
boolean tempsDemiActive = true;
bool boutonPresse = false;
static int8_t Envoi_paquet[6] = {0} ;
void Envoi_commande(int8_t commande, int16_t donnees );
void setup()
{
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT);
delay(500);//Requires 500ms to wait for the MP3 module to initialize
mp3.setVolume(volume);
delay(50);//you should wait for >=50ms between two commands
delay(50);
display.clear();
display.setBrightness(7); // set the brightness to 7 (0:dimmest, 7:brightest)
Wire.begin();
customKeypad.begin();
jeuEtatSet(jeuEtatDemarrage, F("Setup()"));
//--------------------------------- Initialisation EEPROM
eeprom24C.begin();
word eeprCheck; // Mot de test
eeprom24C.readBlock(eeprOffsetCheckWord, (uint8_t *) &eeprCheck, sizeof(eeprCheck));
if (eeprCheck != eeprCheckWord) // Si premier usage
{
Serial.println(F("\n!!!! EEPROM PAS INITIALISEE !!!!"));
while(1)
{
// LED Warning
}; // Arrêt d programme
}
else
{
Serial.println(F("\tEEPROM OK"));
}
desamInitialisation();
SPI.begin();
mfrc522.PCD_Init();
myServo.attach(servoPin);
myServo.write(0);
for (int l = 0; l < ledNumber; l++)
{
pinMode(ledColorIndex[l], OUTPUT);
digitalWrite(ledColorIndex[l], !ledOn);
}
//--------------------------------- LCD
lcdA.init();
lcdB.init();
lcdA.backlight();
lcdB.backlight();
lcdA.createChar(0, lcdGlitchSnow); // Pour glitcher LCD
lcdA.createChar(1, lcdGlitchSnowLittle);
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("GEARS AIRSOFT"));
mp3.playWithFileName(0x01,0x09);
delay(3000 / timeFactor);
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("Activation"));
delay(3000 / timeFactor);
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("Activation OK"));
digitalWrite(ledColorIndex[ledColorGreen], HIGH);
delay(3000 / timeFactor);
digitalWrite(ledColorIndex[ledColorGreen], !ledOn); // Éteindre la LED verte
}
void loop() {
digitalWrite(ledColorIndex[ledColorYellow], HIGH);
selectedMode = selectGameMode();
selectedTime = selectGameTime();
disarmCode = selectDisarmCode(); // Appeler la configuration du code de désarmement après la sélection du temps
//selectedMode = 1;
//selectedTime = 1;
//disarmCodeLength = 4;
//disarmCode = "1111";
gameStart();
gestionTempsDemi(); // Appeler la fonction pour gérer le temps demi
digitalWrite(ledColorIndex[ledColorYellow], !ledOn);
}
//------------------------------------- Désamorçage
void desamInitialisation()
{
for (int d = 0; d < desamFctNombre; d++)
{
pinMode(desamPin[d], INPUT_PULLUP); // Tout les boutons à GND d'un côté
}
}
void desamNewKeys(int dimArray) // Nouvelles clefs désamorçage dans structure rndArray
{
int rndCpt = 0; // Pour compter les chiffres
for (int r = 0; r < dimArray; r++) {
rndArray[r].sorti = false; // Reset flag
}
while(true){
int rndNew = random(0, dimArray);
if (!rndArray[rndNew].sorti) // Si pas encore sorti
{
rndArray[rndNew].sorti = true; // Marquer chiffre sorti
rndArray[rndCpt].nombre = rndNew; // Enregistrer ce nombre
rndCpt ++;
if (rndCpt >= dimArray) // Si tirage terminé
{
break; // While terminé
}
}
}
if (rndArrayInTest) // Si en test
{
for (int n = 0; n < dimArray; n ++) // Mettre des nombres fixes
{
rndArray[n].nombre = n;
}
}
}
int desamFilLecture() // Lectute des fils de désamorçage
{
for (int f = 0; f < desamFctNombre; f++)
{
if (digitalRead(desamPin[f]) == desamEtatOn) // Si fil interrompu
{
return f;
}
}
return -1;
}
void gameStart() {
desamNewKeys(desamFctNombre); // Tirage d'une nouvelle table de hazard
timerDuration = selectedTime * 60L * (1000L / timeFactor);
startTime = millis();
bombExploded = false;
digitalWrite(ledColorIndex[ledColorRed], HIGH);
jeuEtatSet(jeuEtatEnCours, F("while (millis() - startTime"));
int desamFil = -1; // Pas de fil interrompu
lcdGlitchOn = false; // Glitch pas actif
// Boucle principale du jeu
while (millis() - startTime < timerDuration && !bombExploded) {
mp3.playWithFileName(0x01, 0x07);
unsigned long remainingTime = timerDuration - (millis() - startTime);
unsigned long remainingMinutes = remainingTime / 1000 / 60;
unsigned long remainingSeconds = (remainingTime / 1000) % 60;
if (!lcdGlitchOn) { // Si écran pas en mode glitch
lcdB.clear();
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Temps restant:"));
lcdA.setCursor(0, 1);
lcdA.print(remainingMinutes);
lcdA.print(F(" min "));
lcdA.print(remainingSeconds);
lcdA.print(F(" sec"));
}
disarmBomb(); // Appeler la fonction de désamorçage à chaque itération de la boucle principale
// Vérification si le bouton poussoir est enfoncé
if (digitalRead(BUTTON_PIN) == HIGH) {
// Ajouter une minute au minuteur
timerDuration += 60 * 1000;
// Attendre un petit moment pour éviter la détection multiple du bouton
delay(DEBOUNCE_DELAY);
}
delay(900);
}
// Vérification de l'état de la bombe à la sortie de la boucle principale
if (!bombExploded && millis() - startTime >= timerDuration) {
gestionExplosion();
}
// Éteindre toutes les LED à la fin du jeu
for (int l = 0; l < ledNumber; l++) {
digitalWrite(ledColorIndex[l], !ledOn);
}
}
void gestionLcdGlitch() {
Serial.println(F("LCD Glitch"));
lcdGlitchOn = true;
lcdGlitchLoop = (lcdGlitchLoop + 1) % 20;
delay(5);
int lcdCol=random(4);
lcdA.setCursor (19-lcdGlitchLoop, lcdCol);
int r = random(100);
lcdA.print(r > 20 ? ' ' : (r > 20/2 ? char(0) : char(1)));
}
void gestionTempsDemi() {
static bool tempsDemiReduced = false; // Variable statique pour suivre si le temps demi a déjà été réduit
// Logique pour gérer le temps demi
int filTempsDemi = desamFilLecture();
if (filTempsDemi != -1 && desamFct == desamFctTempsDemi && !tempsDemiReduced) {
// Le fil temps demi est déconnecté, donc réduire de moitié le temps restant
unsigned long tempsRestant = timerDuration - (millis() - startTime);
timerDuration = tempsRestant / 2;
tempsDemiReduced = true; // Marquer que le temps demi a été réduit
}
}
void gestionExplosion() {
bombExploded = true;
jeuEtatSet(jeuEtatBombeToOff, F("disarmBomb()"));
digitalWrite(ledColorIndex[ledColorGreen], !ledOn); // Éteindre la LED verte
myServo.write(90);
delay(2000);
myServo.write(0);
for (int l = 0; l < ledNumber; l++)
{
digitalWrite(ledColorIndex[l], !ledOn);
}
jeuEtatSet(jeuEtatBombeBoom, F("Explosion détectée"));
digitalWrite(ledColorIndex[ledColorRed], HIGH);
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("BOOOOM !"));
lcdB.setCursor(0, 1);
lcdB.print(F("Bombe Explosee !"));
delay(3000);
// Attendre la lecture du badge NFC
waitForNFCCardOGA();
}
void displayMessage(LiquidCrystal_I2C& lcd, const String& line1, const String& line2, int delayTime = 1000)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
delay(delayTime / timeFactor);
}
bool isRFIDCardPresent()
{
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
{
return true;
}
return false;
}
void checkRFIDCard() {
if (isRFIDCardPresent())
{
digitalWrite(ledColorIndex[ledColorRed], HIGH);
delay(1000);
digitalWrite(ledColorIndex[ledColorRed], !ledOn);
}
}
String selectDisarmCode()
{
jeuEtatSet(jeuEtatSelCode, F("disarmCodeSetup()"));
String disarmCode = "";
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Longueur du code (4-8):"));
int selectedLength = 0;
while (selectedLength < 4 || selectedLength > 8)
{
char key = customKeypad.getKey();
if (key >= '4' && key <= '8')
{
selectedLength = key - '0';
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print("Longueur choisie:");
lcdA.print(selectedLength);
delay(1000);
}
}
disarmCodeLength = selectedLength;
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print("Entrez le code:");
delay(1000);
disarmCode = "";
while (disarmCode.length() < disarmCodeLength)
{
char key = customKeypad.getKey();
if (((key >= '0' && key <= '9') || (key >= 'A' && key <= 'F')) && key != NO_KEY)
{
disarmCode += key;
lcdA.print('*');
}
else if (key == '#')
{
if (disarmCode.length() == disarmCodeLength)
{
// Code complet, sortir de la boucle
break;
}
}
delay(100);
}
jeuEtatSet(jeuEtatSelCode, String(disarmCode));
delay(1000);
digitalWrite(ledColorIndex[ledColorYellow], !ledOn); // Eteindre la LED Jaune
digitalWrite(ledColorIndex[ledColorGreen], ledOn); // Allumez la LED verte
displayMessage(lcdA, "Code valide:", disarmCode, 2000);
delay(2000);
digitalWrite(ledColorIndex[ledColorGreen], !ledOn); // Eteindre la LED Verte
return disarmCode;
}
void displayDisarmCode(const String& code)
{
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("Entrez le code:"));
lcdB.setCursor(0, 1);
for (size_t i = 0; i < code.length(); ++i)
{
lcdB.print('*');
}
}
void disarmBomb()
{
static String enteredCode = ""; // Variable statique pour conserver sa valeur entre les appels
static unsigned long lastDisplayTime = 0;
char key = customKeypad.getKey();
if (key != NO_KEY && ((key >= '0' && key <= '9') || (key >= 'A' && key <= 'F')) && enteredCode.length() < disarmCodeLength && !bombExploded)
{
enteredCode += key;
lastDisplayTime = millis();
}
// Afficher le code pendant une période définie après chaque pression de touche
if (millis() - lastDisplayTime < 3000)
{
displayDisarmCode(enteredCode);
}
else
{
displayDisarmCode(""); // Effacer le code après la période définie
enteredCode = ""; // Réinitialiser le code pour la nouvelle partie
}
// Vérifier si le code a atteint la longueur spécifiée
if (enteredCode.length() == disarmCodeLength)
{
if (!bombExploded) // Vérifier si la bombe n'a pas encore explosé
{
if (enteredCode == disarmCode)
BombeDesamorcee();
}
}
}
void BombeDesamorcee() {
bombExploded = true;
digitalWrite(ledColorIndex[ledColorGreen], ledOn); // Allumez la LED verte
delay(2000);
digitalWrite(ledColorIndex[ledColorYellow], !ledOn); // Eteindre la LED Jaune
jeuEtatSet(jeuEtatBombeToOff, F("disarmBomb()"));
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("Bombe desamorcee !"));
delay(3000);
// Attendre la lecture du badge NFC
waitForNFCCardOGA();
}
int selectGameMode()
{
jeuEtatSet(jeuEtatSelMode, F("selectGameMode()"));
int selectedMode = -1;
for (int i = 0; i < 5; i++)
{
displayMessage(lcdB, "Mode de Jeux (" + String(i + 1) + ")", gameModes[i], 1000);
}
displayMessage(lcdB, F("Faites votre choix:"), F("(1-5)"), 500);
while (selectedMode < 1 || selectedMode > 5)
{
char key = customKeypad.getKey();
if (key != NO_KEY && key >= '1' && key <= '5')
{
selectedMode = key - '0';
lcdB.clear();
lcdB.setCursor(0, 0);
lcdB.print(F("Mode choisi: "));
lcdB.print(selectedMode);
lcdB.setCursor(0, 1);
lcdB.print(F(" - "));
lcdB.print(gameModes[selectedMode - 1]);
delay(3000 / timeFactor);
}
}
jeuEtatSet(jeuEtatSelMode, gameModes[selectedMode - 1]);
return selectedMode;
}
int selectGameTime()
{
int inputTime = 0;
bool timeSelectionComplete = false;
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Temps (min):"));
jeuEtatSet(jeuEtatSelTime, "Loop()");
while (!timeSelectionComplete)
{
char key = customKeypad.getKey();
if (key >= '0' && key <= '9')
{
inputTime = inputTime * 10 + (key - '0');
lcdA.print(key);
}
else if (key == '#')
{
timeSelectionComplete = true;
}
else if (key == '*')
{
if (inputTime > 0)
{
inputTime = inputTime / 10;
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Temps (min):"));
lcdA.print(inputTime);
}
}
delay(100);
}
jeuEtatSet(jeuEtatSelTime, String(inputTime));
return inputTime;
}
bool waitForNFCCardOGA()
{
jeuEtatSet(jeuEtatAttNfc, F("waitForNFCCardOGA()"));
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Veuillez contacter"));
lcdA.setCursor(0, 1);
lcdA.print(F("votre ORGA..."));
unsigned long startTime = millis(); // Enregistrez le temps au début
// La carte NFC a été détectée
digitalWrite(ledColorIndex[ledColorGreen], !ledOn); // Eteindre la LED verte
while (true) // Tant que le badge ORGA n'a pas été lu
{
String nomCarte = F("-");
while (nomCarte == F("-"))
{
nomCarte = uidGetNameByCardRead();
digitalWrite(ledColorIndex[ledColorRed], ledOn); // Allumez la LED rouge
}
// Réinitialiser l'état du module RFID
digitalWrite(ledColorIndex[ledColorRed], ledOn); // Allumez la LED rouge
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
//Serial.println(nomCarte);
if (nomCarte == F("ORGA"))
{
digitalWrite(ledColorIndex[ledColorGreen], ledOn); // Allumez la LED verte
jeuEtatSet(jeuEtatArrete, F("waitForNFCCard()"));
delay(2000);
lcdA.clear();
lcdA.setCursor(0, 0);
lcdA.print(F("Veuillez choisir"));
lcdA.setCursor(0, 1);
lcdA.print(F("le mode de jeux."));
return true; // Si une carte est lue, retournez true
}
else
{
Serial.println("Carte " + nomCarte + " INVALIDE");
mp3.playWithFileName(0x01,0x06);
ledWarning(3, 400);
//return false;
}
}
}
//------------------------------------- Etats du jeu
void jeuEtatSet(int etat, String remarque)
{
jeuEtat = etat;
Serial.println("Etat " + jeuEtatLabel[etat]);
if (remarque != "")
{
Serial.println("\t" + remarque);
}
}
String uidGetNameByCardRead() // Retourne le nom via lecture badge
{
String uidCard = uidLireCarte(true);
int uidIndex = uidRecherche(uidCard);
//Serial.println(uidIndex);
if (uidIndex != -1) // Si UID trouvé
{
uidEeprLireUn(uidIndex);
return (String)uidMem.nom; // Retourne le nom
}
return "-"; // Pas trouvé
}
//------------------------------------- Rechercher UID
int uidRecherche(String uidRech)
{
for (int u = 0; u < uidNombre; u ++)
{
uidEeprLireUn(u);
if ((String)uidMem.uid == uidRech)
{
return u;
}
}
return -1; // Pas trouvé
}
String uidRechercheNameByUid(String uidRech)
{
int uidIndex = uidRecherche(uidRech);
if (uidIndex != -1) // Si UID trouvé
{
uidEeprLireUn(uidIndex);
return (String)uidMem.nom; // Retourne le nom
}
return "-"; // Pas trouvé
}
//------------------------------------- Rechercher UID NOM
int uidRechercheNom(String uidNomRech)
{
for (int u = 0; u < uidNombre; u ++)
{
uidEeprLireUn(u);
if ((String)uidMem.nom == uidNomRech)
{
return u;
}
}
return -1; // Pas trouvé
}
//------------------------------------- lire 1 UID depuis EEPROM dans uidWork
void uidEeprLireUn(int uidIndex)
{
int eeprAddress = eeprOffsetUid + (uidRecordSize * uidIndex);
eeprom24C.readBlock(eeprAddress, (uint8_t *) &uidMem, sizeof(uidMem));
}
//------------------------------------- Lister les UID dans l'EEPROM
void uidEeprList()
{
Serial.println(F("Contenu de l'EEPROM"));
for (int a = eeprOffsetUid; a < eeprOffsetUid + (uidNombre * uidRecordSize); a += uidRecordSize)
{
eeprom24C.readBlock(a, (uint8_t *) &uidMem, sizeof(uidMem));
Serial.println((String)uidMem.uid + "\t" + (String)uidMem.nom);
}
}
String uidLireCarte(boolean echo) // Lire la carte retourne le UID
{
String uid="";
if(mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
{
for(int i=0;i<mfrc522.uid.size;i++)
{
uid.concat(String(mfrc522.uid.uidByte[i]<0x10 ? "0" : ""));
uid.concat(String(mfrc522.uid.uidByte[i],HEX));
}
uid.toUpperCase();
if (echo)
{
Serial.print(F("\nUID : "));
Serial.println(uid);
}
}
return uid;
}
void ledWarning(int loop, unsigned long time)
{
for (int l = 0; l < loop; l ++)
{
digitalWrite(ledColorIndex[ledColorRed], ledOn);
delay(time);
digitalWrite(ledColorIndex[ledColorRed], !ledOn);
delay(time);
}
}