Hello,
I've come to ask you for help with a code to make a password. I don't understand very well how it works especially from the first If loop. If someone could explain it to me that would be very kind. In the If loop it is especially the "While" that I do not understand:
a=keypad.getKey();
while(a == NO_KEY)
a=keypad.getKey();
Serial.print(a);
What does the "NO_KEY" correspond to?
What does the "kepad.getKey" correspond to?
why write "a=keypad.getKey();" before and after the "While"?
why do the whole if loop like this?
Concerning the Can part, what does CAN.sendMsgBuf (0x10, 0, 1, Value); correspond to?
#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);
}
}