hi guys , i have problem to save the date , time out , time in and the user( matricule ) on EXCEL
PLS HELP GUYS , this is the code
#include <LiquidCrystal.h>
#include <Keypad.h>
/*-------------------------------KEYPAD---------------------------------------*/
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 3; //number of columns on the keypad
char key_pressed;
int i ;
int j ;
int PIR = A0;
int LOCK = A4;
const int BUTTON = A3; // boutton pour la sorie placer dans la face de porte dans l'enterieur
char keymap[numRows][numCols]=
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {4, 5, 6, 7};//Rows 0 to 3
byte colPins[numCols] = { A5, 2, 3};//Columns 0
Keypad mykeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
/*-------------------------------CONSTANTS------------------------------------*/
LiquidCrystal lcd(13,12,11,10,9,8); //LCD
char MAT[5][4] = {"1111","2222","3333","4444","5555"}; //MATRICULE
char PASS[5][4] = {"1111","2222","3333","4444","5555"};// MOT DE PASSE
int VAS=0;// ENRGISTRE FIHA VALEUR DE 1 JUSQU'A 5
char mat[5];
char password[5];
//boolean changedPassword = false;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
Serial.println("LABEL,Date,Matricule,Time IN,Time OUT");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53)
lcd.begin(16, 2); //Setup the LCD's number of columns and rows
pinMode(BUTTON, INPUT);// BUTTON
pinMode(A1, OUTPUT); // LED RED
pinMode(A2, OUTPUT); // LED GREEN
pinMode(A0, INPUT);//PIR
pinMode(A4, OUTPUT); //LOCK
}
void loop() {
if(digitalRead(PIR) == HIGH)
{
lcd.setCursor(0,0);
lcd.print("ENTER MAT: ");
lcd.setCursor(0,1);
lcd.print("");
key_pressed = mykeypad.getKey();
if (key_pressed == '0' || key_pressed == '1' || key_pressed == '2' || key_pressed == '3' || key_pressed == '4' || key_pressed == '5' || key_pressed == '6' || key_pressed == '7' || key_pressed == '8' || key_pressed == '9' ) {
mat[i++] = key_pressed;
;
lcd.setCursor(i, 2);
lcd.print(key_pressed);
if (i == 4)
{
for(int l=0;l<4;l++)
{
int resultat = 0; //ajout de resultat pour afficher la valeur renvoyer par la comparaison
resultat = strncmp(mat, MAT[l],4) ; //on compare les mots
if(resultat == 0)
{
VAS=l;
i =0;
lcd.setCursor(0, 0);
lcd.print(" Mat Accepted");
lcd.setCursor(0, 1);
lcd.print(" ");
digitalWrite(A2, HIGH);
delay(300);
digitalWrite(A2, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Password ");
delay(400);
while (j < 4) {
key_pressed = mykeypad.getKey();
if (key_pressed== '0' || key_pressed== '1' || key_pressed== '2' || key_pressed== '3' || key_pressed== '4' || key_pressed== '5' || key_pressed== '6' || key_pressed== '7' || key_pressed== '8' || key_pressed== '9')
{
password[j++] = key_pressed;
lcd.setCursor(j, 2);
lcd.print("*");
}
key_pressed=0;
}
if (!strncmp(password, PASS[VAS],4))
{
j=0;
lcd.setCursor(0, 0);
lcd.print("Pass Accepted");
lcd.setCursor(0, 1);
lcd.print("WELCOME");
digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
digitalWrite(A2, HIGH);
delay(500);
Serial.print("DATA,DATE," + MAT[5][4]);//send the Name to excel
Serial.print(",");
Serial.print(MAT[5][4]); //send the Number to excel
Serial.print(",");
Serial.print("");
Serial.print(",");
Serial.println("TIME");
digitalWrite(LOCK, LOW);
digitalWrite(A2, LOW);
delay(300);
lcd.clear();
}
else
{
j=0;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Wrong Password");
digitalWrite(A1,HIGH);
delay(200);
digitalWrite(A1,LOW);
}
}
else
{
lcd.setCursor(0, 0);
lcd.print("Wrong Mat");
lcd.setCursor(0, 1);
lcd.print("Try again PLS");
digitalWrite(A1,HIGH);
delay(200);
digitalWrite(A1,LOW);
delay(200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Mat");
lcd.setCursor(0, 1);
i =0;
}
}
}
}
}
else
{
lcd.clear();
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if(digitalRead(BUTTON) == HIGH){
j=0;
digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
digitalWrite(A2, HIGH);
delay(500);
digitalWrite(LOCK, LOW);
digitalWrite(A2, LOW);
delay(1000);
/* Serial.print(",");
Serial.print(MAT[5][4]); //send the Number to excel
Serial.print(",");
Serial.print("");
Serial.print(",");
Serial.println("TIME");*/
lcd.clear();
}
return loop();
}