Created
May 30, 2017 16:08
-
-
Save jonathdb/34d9dadf27cf273371174ffa1429ba44 to your computer and use it in GitHub Desktop.
functions to the Alt.ino program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int readBlock(int blockNumber, byte arrayAddress[]) { | |
int largestModulo4Number=blockNumber/4*4; | |
int trailerBlock=largestModulo4Number+3;//determine trailer block for the sector | |
/*****************************************authentication of the desired block for access***********************************************************/ | |
byte status = scanner.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(scanner.uid)); | |
if (status != MFRC522::STATUS_OK) { | |
//Serial.print("PCD_Authenticate() failed (read): "); | |
//Serial.println(scanner.GetStatusCodeName(status)); | |
skrivFeilmld(); | |
return 3; //return "3" as error message | |
} | |
/*****************************************reading a block***********************************************************/ | |
byte buffersize = 18;//we need to define a variable with the read buffer size, since the MIFARE_Read method below needs a pointer to the variable that contains the size... | |
status = scanner.MIFARE_Read(blockNumber, arrayAddress, &buffersize);//&buffersize is a pointer to the buffersize variable; MIFARE_Read requires a pointer instead of just a number | |
if (status != MFRC522::STATUS_OK) { | |
//Serial.print("MIFARE_read() failed: "); | |
//Serial.println(scanner.GetStatusCodeName(status)); | |
skrivFeilmld(); | |
return 4; //return "4" as error message | |
} | |
return 1; | |
} | |
void registrerElev(){ | |
for (int j=0 ; j<16 ; j++){ //print the block contents | |
name += char(readbackblock[j]); //transmits the ASCII numbers as human readable characters to serial monitor | |
} | |
//Writing to Excel and LCD | |
Serial.print("DATA,TIME,"); //writes the date in the first column A and the time in column B | |
Serial.print(name); | |
Serial.println(); //Goes to next row on the second run | |
clearLCD(); | |
lcd.setCursor(0, 0); | |
lcd.print(name); | |
lcd.setCursor(0, 1); | |
lcd.print("er registrert."); | |
pixels.setBrightness(200); | |
for(int i=0;i<NUMPIXELS;i++){ | |
pixels.setPixelColor(i, pixels.Color(0,255,0)); // Moderately bright green color. | |
pixels.show(); | |
} | |
delay(2000); | |
pixels.setBrightness(0); | |
pixels.show(); | |
scanner.PCD_StopCrypto1(); | |
clearLCD(); | |
name = ""; | |
} | |
void clearLCD(){ | |
lcd.setCursor(0, 0); | |
lcd.clear(); | |
lcd.setCursor(0, 1); | |
lcd.clear(); | |
//digitalWrite(greenLeds, LOW); | |
//digitalWrite(redLeds, LOW); | |
} | |
void skrivFeilmld(){ | |
clearLCD(); | |
lcd.setCursor(0, 0); | |
lcd.print("En feil oppstod"); | |
lcd.setCursor(0, 1); | |
lcd.print("ikke registrert."); | |
pixels.setBrightness(200); | |
for(int i=0;i<NUMPIXELS;i++){ | |
pixels.setPixelColor(i, pixels.Color(255,0,0)); // Moderately bright red color. | |
pixels.show(); | |
} | |
delay(2000); | |
pixels.setBrightness(0); | |
pixels.show(); | |
feilRegistrering = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment