arduino ne détecte pas le passage du niveau haut vers le niveau bas de mon bouton poussoir, ou vice versa , voic mon code de l'aide s'il vous plait , le projet consiste à utiliser des cartes rfid pour simuler des produit et le lecteurs lit ceux ci , apres on a la validation par la caissière qui le fait via un bouton poussoir , or problème la détection du passage du niveau haut vers le niveau bas et vice versa n'est pas faite par arduino , je ne comprends pas pourquoi et j'ai tout essayé ,, de l'aide svp
/*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <MFRC522.h>
int pinBouton;
boolean etatAllumage;
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 2
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
String UID;
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
struct Produit {
String code;
String nom;
int prix;
bool etach;
};
int cpt =0;
Produit Stock[5],Gprod[5];
void setup() {
Stock[0]={"130253248101","Bambi chocolat",1275,false};
Stock[1]={"133195164117","Soda",375,false};
Stock[2]={"53163170117","Gourde",1350,false};
Stock[3]={"68203159213","Savon",850,false};
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinBouton = 2;
pinMode(pinBouton,INPUT);
etatAllumage=0;
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
lcd.init();
lcd.backlight();
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
}
}
void loop() {
// lcd.print("Attente ");
// lcd.setCursor(0,1);
// lcd.print(" de clients ...");
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
// Serial.print(F("Reader "));
// Serial.print(reader);
// Serial.print(F(" -- "));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
// Serial.print("My IUD : " + UID);
// Serial.println();
//La caissière
if (reader==0){
lcd.clear();
for (int i =0; i<5; i++)
{
if (UID == Stock[i].code )
{
Gprod[cpt].nom = Stock[i].nom;
Gprod[cpt].code = Stock[i].code;
Gprod[cpt].prix = Stock[i].prix;
Gprod[cpt].etach = Stock[i].etach;
lcd.print(Gprod[cpt].nom);
cpt=cpt+1;
}
}
boolean etatBouton = digitalRead(pinBouton);
delay(1);
if (etatBouton)//si bouton appuyé (donc le pin indique 0 car il est en mode INPUT_PULLUP)
{
if (!etatAllumage) //si etatAllumage à 1
{
etatAllumage=1; //on le passe à 0
}
}
if (etatAllumage)
{
lcd.init();
int somme =0;
cpt=0;
for (int i =0; i<5; i++)
{
somme = somme+ Gprod[i].prix;
for (int j =0; j<5; j++)
{
if (Gprod[i].code==Stock[j].code)
{
Stock[j].etach = true;
}
}
Gprod[cpt].nom = "";
Gprod[cpt].code = "";
Gprod[cpt].prix = 0;
Gprod[cpt].etach = false;
}
lcd.print("total : ");
lcd.print(somme);
}
}
//La sortie
// if (){}
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
UID ="" ;
for (byte i = 0; i < bufferSize; i++) {
// Serial.print(buffer[i] < 0x10 ? " 0" : " ");
UID=UID+String(buffer[i]) ;
}
}