this void prints rfid value on lcd screen;
when include void in loop();
its that, wanna store value gives out int. can make name tags each rfid card. ex;
hope kinda makes sense. :/
thanks guys!
this looks far, can make print value, want print out names.
code: [select]
void dump_byte_array(byte *buffer, byte buffersize) {
(byte x=0; x < buffersize; x++){
lcd.print(buffer[x] < 16 ? "0" :""); //value cannot bigger 16 digits
lcd.print(buffer[x], hex);
}
}
when include void in loop();
code: [select]
dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size);
its that, wanna store value gives out int. can make name tags each rfid card. ex;
code: [select]
if(valueoncard=="81949b75"){
lcd.print("name1");
}else if(valueoncard=="839fa9d5"){
lcd.print("name2");
}else if(dvalueoncard=="938c8f00"){
lcd.print("name3");
}else if(valueoncard=="45e09f2c"){
lcd.print("name4");
}else{
lcd.print("your card has not been entered database. sorry frown emoticon");
}
hope kinda makes sense. :/
thanks guys!
this looks far, can make print value, want print out names.
code: [select]
#include <spi.h>
#include <mfrc522.h>
#include <liquidcrystal.h>
liquidcrystal lcd (7,6,5,4,3,2);
#define rst_pin 9 // configurable, see typical pin layout above
#define ss_pin 10 // configurable, see typical pin layout above
byte id;
mfrc522 mfrc522(ss_pin, rst_pin); // create mfrc522 instance.
// number of known default keys (hard-coded)
// note: synchronize nr_known_keys define defaultkeys[] array
#define nr_known_keys 8
// known keys, see: https://code.google.com/p/mfcuk/wiki/mifareclassicdefaultkeys
byte knownkeys[nr_known_keys][mfrc522::mf_key_size] = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // ff ff ff ff ff ff = factory default
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // a0 a1 a2 a3 a4 a5
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // b0 b1 b2 b3 b4 b5
{0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4d 3a 99 c3 51 dd
{0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1a 98 2c 7e 45 9a
{0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // d3 f7 d3 f7 d3 f7
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // aa bb cc dd ee ff
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 00 00 00 00 00 00
};
/*
* initialize.
*/
void setup() {
lcd.begin(16, 2);
lcd.print("scan card");
lcd.setcursor(0,2);
serial.begin(9600); // initialize serial communications pc
while (!serial); // nothing if no serial port opened (added arduinos based on atmega32u4)
spi.begin(); // init spi bus
mfrc522.pcd_init(); // init mfrc522 card
serial.println(f("try used default keys print block 0 of mifare picc."));
}
/*
* helper routine dump byte array hex values serial.
*/
void dump_byte_array(byte *buffer, byte buffersize) {
for (byte x=0; x < buffersize; x++){
lcd.print(buffer[x] < 16 ? "0" :"");
lcd.print(buffer[x], hex);
}
}
void uids(){
//you need find way turn value int
//you've tried including void , such.
if(dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size)=="81949b75"){
lcd.print("name1");
}else if(dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size)=="839fa9d5"){
lcd.print("name2");
}else if(dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size)=="938c8f00"){
lcd.print("name3");
}else if(dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size)=="45e09f2c"){
lcd.print("name4");
}else{
lcd.print("your card has not been entered database. sorry frown emoticon");
}
}
*/
void dump_byte_array1(byte *buffer, byte buffersize) {
(byte = 0; < buffersize; i++) {
//serial.print(buffer[i] < 0x10 ? " 0" : " ");
serial.print(buffer[i] < 16 ? "0" : "");
//serial.print(buffer[i], hex);
}
}
/*
* try using picc (the tag/card) given key access block 0.
* on success, show key details, , dump block data on serial.
*
* @return true when given key worked, false otherwise.
*/
boolean try_key(mfrc522::mifare_key *key)
{
boolean result = false;
byte buffer[18];
byte block = 0;
byte status;
// serial.println(f("authenticating using key a..."));
status = mfrc522.pcd_authenticate(mfrc522::picc_cmd_mf_auth_key_a, block, key, &(mfrc522.uid));
if (status != mfrc522::status_ok) {
// serial.print(f("pcd_authenticate() failed: "));
// serial.println(mfrc522.getstatuscodename(status));
return false;
}
// read block
byte bytecount = sizeof(buffer);
status = mfrc522.mifare_read(block, buffer, &bytecount);
if (status != mfrc522::status_ok) {
// serial.print(f("mifare_read() failed: "));
// serial.println(mfrc522.getstatuscodename(status));
}
else {
// successful read
result = true;
dump_byte_array((*key).keybyte, mfrc522::mf_key_size);
serial.println();
// dump block data
serial.print(f("block ")); lcd.print(block); serial.print(f(":"));
dump_byte_array(buffer, 16);
serial.println();
}
serial.println();
mfrc522.picc_halta(); // halt picc
mfrc522.pcd_stopcrypto1(); // stop encryption on pcd
return result;
}
/*
* main loop.
*/
void loop() {
// new cards
if ( ! mfrc522.picc_isnewcardpresent())
return;
// select 1 of cards
if ( ! mfrc522.picc_readcardserial())
return;
// show details of picc (that is: tag/card)
serial.print(f("card uid:"));
dump_byte_array1(mfrc522.uid.uidbyte, mfrc522.uid.size);
dump_byte_array(mfrc522.uid.uidbyte, mfrc522.uid.size);
delay(1000);
lcd.clear();
lcd.print("scan card");
lcd.setcursor(0,2);
//lcd.clear();
serial.println();
}
"void" return type of function , means nothing returned program segment calls function.
"dump_byte_array(byte *buffer, byte buffersize)" function, not void.
"dump_byte_array(byte *buffer, byte buffersize)" function, not void.
Arduino Forum > Using Arduino > Programming Questions > Void as an int?
arduino
Comments
Post a Comment