This is an update for my previous project. I am making a credit system. Exactly like the ones in arcade games where you load up your card an play games till the balance runs out. This is a skeleton for any project I need to make in the future.
I want to load up some points in a rfid card- DONE
then I want to display the amount in the card - DONE
when I press a certain button, I want the balance in the card to increase by $100 and that value should be displayed on the LCD Display - NOT DONE
I also want to make a system where if the card is placed and another button is pressed, the value in the card should decrease by $50 and it should show on the LCD that the product is
dispensed - NOT DONE
I am a new Arduino developer and I would really like some help with the above tasks. If someone could please help me and write some code for it or at least help me, I would be very grateful to them and hold them with very high regard in my future programming life.
Here is some of my code that I wrote myself with some help from the forum a little earlier.
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
LiquidCrystal_I2C lcd(0x27,20,4);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init();
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
}
//*****************************************************************************************//
void loop() {
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
//some variables we need
byte block;
byte len;
MFRC522::StatusCode status;
//-------------------------------------------
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
//-------------------------------------------
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
//-------------------------------------------
lcd.print(F("Credits: "));
byte buffer1[18];
block = 2;
len = 18;
//------------------------------------------- GET FIRST NAME
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 2, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
if (status != MFRC522::STATUS_OK) {
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Read(block, buffer1, &len);
if (status != MFRC522::STATUS_OK) {
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
//PRINT FIRST NAME
for (uint8_t i = 0; i < 16; i++)
{
if (buffer1[i] > 32)
{
Serial.write(buffer1[i]);
lcd.print((char)buffer1[i]);
}
}
delay(3000); //change value if you want to read cards faster
lcd.clear();
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}