Salut! J'ouvre un sujet car j'ai un soucis que je n'avais rencontré avant
En essayant de téléverser mon code aujourd'hui et vérifier ce que me sortais le moniteur, je n'arrive plus à "afficher" la fenêtre.
En fait une nouvelle fenêtre est bien créé, mais impossible de mettre le focus dessus
Si je clique sur la fenêtre, rien ne s'affiche.
J'ai essayé de commenter / décommenter ma ligne "Serial.begin(115200);", mais ça n'a rien changé.
Voilà le code (qui permet de lire des adresse hexadecimales de cartes RFID) à titre indicatif:
#include <Debug.h>
#include <PN5180.h>
#include <PN5180ISO15693.h>
/*
*/
const int ledred = 7;
const int ledgreen = 6;
// The number of PN5180 readers connected
const byte numReaders = 3; /// A MODIFIER
// What is the "correct" UID that should be detected by each reader
uint8_t correctUid[][8] =
{
{0x8A,0x9F,0x9D,0xA4,0x50,0x1,0x4,0xE0}, //TAG 1
{0xB,0x8A,0xC6,0x6A,0x0,0x1,0x4,0xE0} //TAG 2
};
//Si ce tag est lu par un des lecteurs, le puzzle sera reset
uint8_t resetUid[][8] = {{0xD1,0xD2,0x48,0x2A,0x50,0x1,0x4,0xE0}}; //TAG 1}
//Valeur par défaut quand il n'y a pas de tag
uint8_t noUid[][8] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}; //TAG 1}
//Serial.println("Etape 1");
// GLOBALS
// Each PN5180 reader requires unique NSS, BUSY, and RESET pins,
// as defined in the constructor below
PN5180ISO15693 nfc[] = {
PN5180ISO15693(22,24,26), // Pins correspondants aux fonstions des lecteurs
PN5180ISO15693(28,30,32), // works
PN5180ISO15693(34,36,38), // works
//MISO BLEU 50
//MOSI VERT 51
//SCK JAUNE 52
};
// Array to record the value of the last UID read by each reader
uint8_t lastUid[numReaders][8];
// the setup function runs once when you press reset or power the board
void setup() {
Serial.println("Etape 1");
pinMode(ledred,OUTPUT);// Led rouge
pinMode(ledgreen,OUTPUT);// Led verte
Serial.begin(115200);
Serial.println("RFID Tirroir, escape pirate");
for(int i=0; i<numReaders; i++){
Serial.print("Reader #");
Serial.println(i);
Serial.println(F("Initialising..."));
nfc[i].begin();
Serial.println(F("Resetting..."));
nfc[i].reset();
Serial.println(F("Enabling RF field..."));
nfc[i].setupRF();
}
Serial.println(F("Setup Complete"));
}
// the loop function runs over and over again forever
void loop() {
for(int i=0; i<numReaders; i++) {
// Variable to store the ID of any tag read by this reader
uint8_t thisUid[8];
// Try to read a tag ID (or "get inventory" in ISO15693-speak)
ISO15693ErrorCode rc = nfc[i].getInventory(thisUid);
// If the result code was that a card had been read
if(rc == ISO15693_EC_OK) {
// If this is the same ID as we read last frame
if(memcmp(thisUid, lastUid[i], 8) == 0) {
// Nothing to do - move on to the next reader
continue;
}
// If it's a different ID
else {
Serial.print(F("New Card Detected on Reader "));
Serial.print(i);
Serial.print(F("... "));
for (int j=0; j<sizeof(thisUid); j++) {
Serial.print(thisUid[j],HEX);
Serial.print(" ");
}
Serial.println();
// Update the array that keeps track of most recent ID
memcpy(lastUid[i], thisUid, sizeof(lastUid[i][0])*8);
// Has placing this card solved the puzzle?
checkIfPuzzleSolved();
}
}
// If a card cannot be read
else {
// Test if we previously knew about a card (in which case it's just been removed
// The most significant (last) byte of a valid UID should always be 0xE0. e.g. E007C4A509C247A8
if(lastUid[i][7] == 0xE0){
Serial.print("Card ");
for (int j=0; j<sizeof(lastUid[i]); j++) {
Serial.print(lastUid[i][j], HEX);
}
Serial.print(" removed from Reader ");
Serial.println(i);
// Update the array that keeps track of last known ID
memset(lastUid[i], 0, sizeof(lastUid[i][0])*8);
}
#ifdef DEBUG
Serial.print(F("Error in getInventory: "));
Serial.println(nfc[i].strerror(rc));
#endif
}
// Slight delay before checking the next reader
delay(10);
}
// digitalWrite(ledgreen, LOW);
// digitalWrite(ledred, HIGH);
// delay(1000);
// digitalWrite(ledred, LOW);
// digitalWrite(ledgreen, HIGH);
}
void onPuzzleSolved() {
// Activate the relay
digitalWrite(ledred, LOW);
digitalWrite(ledgreen, HIGH);
Serial.print(" Bonne carte ");
// Loop forever
while(true) { delay(1000); }
}
// Check whether all PN5180s have detected the correct tag
void checkIfPuzzleSolved() {
// Test each reader in turn
for(int i=0; i<numReaders; i++){
// If this reader hasn't detected the correct tag
if(memcmp(lastUid[i], correctUid[i], 8) != 0){
// Exit
digitalWrite(ledred, HIGH);
return;
}
}
onPuzzleSolved();
}
Merci!