Skip to content

Instantly share code, notes, and snippets.

@jonathdb
Created May 30, 2017 16:07
Show Gist options
  • Save jonathdb/1bab47a53497dea745c5088d1e358f69 to your computer and use it in GitHub Desktop.
Save jonathdb/1bab47a53497dea745c5088d1e358f69 to your computer and use it in GitHub Desktop.
Programmet som kjorer
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal.h>
#include <SPI.h>//include the SPI bus library
#include <MFRC522.h>//include the RFID reader library
#define SS_PIN 10 //slave select pin
#define RST_PIN 9 //reset pin
String name; //ID of the RFID-card
int block=2; //this is the block number we will read.
byte readbackblock[18]; //Array for reading a block (needs 18 bytes to read)
const int ledPin = 2;
const int NUMPIXELS = 24;
boolean feilRegistrering = false;
MFRC522 scanner(SS_PIN, RST_PIN); // instatiate a MFRC522 reader object.
MFRC522::MIFARE_Key key; //create a MIFARE_Key struct named 'key', which will hold the card information
LiquidCrystal lcd(3, 4, 5, 6, 7, 8); // initialize the library with the numbers of the interface pins
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
pixels.begin(); // This initializes the NeoPixel library.
scanner.PCD_Init(); // Init MFRC522 card (in case you wonder what PCD means: proximity coupling device)
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
Serial.println("CLEARDATA");
Serial.println("LABEL,Tidspunkt,Navn");
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
lcd.print("Arduino er aktiv"); // Print a message to the LCD.
delay(500);
//Show default message
lcd.setCursor(0, 0);
lcd.print("Scan kort for aa");
lcd.setCursor(0, 1);
lcd.print("lagre oppmote");
}
void loop(){
// Look for new cards
if (!scanner.PICC_IsNewCardPresent()) { //if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
return; //if it did not find a new card is returns a '0' and we return to the start of the loop
}
// Select one of the cards
if (!scanner.PICC_ReadCardSerial()) {
return;
}
// Read the ID from the card
if(!readBlock(block, readbackblock) == 1) { //read the block back, check if error in scanning
return;
}
//Only promt a new student if no error.
if(!feilRegistrering) {
registrerElev();
}
//Show default message
lcd.setCursor(0, 0);
lcd.print("Scan kort for aa");
lcd.setCursor(0, 1);
lcd.print("lagre oppmote");
feilRegistrering = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment