Bonjour,
je viens vous demander de l'aide par rapport à un code pour faire un mot de passe. Je ne comprends pas très bien comment il fonctionne surtout à partir de la première boucle If. Si quelqu'un pouvait me l'expliquer cela serait très gentil. Dans la boucle If c'est surtout les " While" que je ne comprends pas :
a=keypad.getKey();
while(a == NO_KEY)
a=keypad.getKey();
Serial.print(a);
à quoi correspond le "NO_KEY" ?
à quoi correspond le "kepad.getKey" ?
pourquoi écrire "a=keypad.getKey();" avant et après le " While "
pourquoi faire toute la boucle if comme cela ?
Concernant la partie Can, à quoi correspond CAN.sendMsgBuf (0x10, 0, 1, Valeur); ?
#include <Keypad.h>
#include <SPI.h>
#include "mcp_can.h"
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
int Code;
unsigned char Valeur[8];
byte rowPins[ROWS] = {7, 5, 3, 2};
byte colPins[COLS] = {4, 9, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(115200); //
delay(100);
START_INIT:
if(CAN_OK == CAN.begin(CAN_500KBPS))
{
Serial.println("CAN BUS Shield init ok!");
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(100);
goto START_INIT;
}
}
void loop(){
char a;
char b;
char c;
char d;
char key = keypad.getKey();
if (key =keypad.getKey()) {
Serial.println ( "");
while(key != NO_KEY)key=keypad.getKey();
Serial.println(" taper le mot de passe ");
a=keypad.getKey();
while(a == NO_KEY)
a=keypad.getKey();
Serial.print(a);
b=keypad.getKey();
while(b == NO_KEY)
b=keypad.getKey();
Serial.print(b);
c=keypad.getKey();
while(c == NO_KEY)
c=keypad.getKey();
Serial.print(c);
d=keypad.getKey();
while(d == NO_KEY)
d=keypad.getKey();
Serial.print(d);
Serial.println ("");
if (a=='2' && b=='6' && c=='0' && d=='1') {
Serial.println(" code valide");
Serial.println("démarrage en cours... ");
Code=1;
}
if (a!='2' | b!='6' | c!='0' | d!='1'){
Serial.println("Code erroné ");
Code=0;
}
Valeur[0]=Code;
CAN.sendMsgBuf(0x10, 0, 1, Valeur);
delay(500);
}
}