Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- #include <SPI.h>
- #include <Keypad.h>
- #include <MFRC522.h>
- #include <LiquidCrystal_I2C.h> //i2C LCD Library
- LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd
- #define SS_PIN 8
- #define RST_PIN 9
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
- char customKey;
- const byte ROWS = 4;
- const byte COLS = 4;
- long passwd = 0;
- long isiku;
- long kartu1;
- long kartu2;
- long kartu3;
- long kartu4;
- int id;
- long beli;
- long dtTombol=0;
- int digit;
- bool notif = true;
- bool mode1=true; //digunakan untuk
- bool mode2=false;
- byte data;
- long saldoSkrg;
- long baca;
- char keys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins [ROWS] = {A0,A1,A2,7};
- byte colPins [COLS] = {6,5,4,3};
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
- void setup()
- {
- lcd.begin(); //set lcd i2c
- lcd.noCursor(); //biar gak ada cursor di lcd
- lcd.clear(); //clear lcd
- Serial.begin(9600); // Initiate a serial communication
- SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- // Serial.println("Put your card to the reader...");
- // Serial.println();
- delay(1000);
- }
- void loop(){
- lcd.setCursor(0,0);
- lcd.print("Pilih Menu");
- lcd.setCursor(0,1);
- lcd.print("A.Tambah B.Kurangi");
- customKey = customKeypad.getKey();
- if(customKey == 'A'){
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Menu Tambah");
- delay(3000);
- cekTekan();
- cekisi();
- /*lcd.clear();
- delay(1000);
- //passwd = 0;
- //isi();
- lcd.setCursor(0,0);
- lcd.print("Dekatkan Kartu");
- delay(3000);
- lcd.clear();
- //isiscan();
- //cekTombol();
- delay(1000);
- isiku = 0;
- scan();
- */
- }
- if(customKey == 'B'){
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Dekatkan Kartu");
- delay(3000);
- lcd.clear();
- //isiscan();
- lcd.clear();
- beli = 0;
- bayar();
- //mulaiisi();
- }
- }
- void cekTekan(){
- lcd.clear();
- dtTombol=0;
- lcd.setCursor(0,0);
- lcd.print("Masukkan Nominal");
- while(mode1){
- char customKey = customKeypad.getKey();
- if(customKey >= '0' && customKey <= '9')
- {
- dtTombol = dtTombol * 10 + (customKey - '0');
- lcd.setCursor(0,1);
- lcd.print(dtTombol);
- }
- if(customKey == 'D'){
- EEPROM.write(3,dtTombol);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Tap Kartu ");
- //Cek ada kartu atau tidak
- if ( ! mfrc522.PICC_IsNewCardPresent()){
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial()){
- return;
- }
- lcd.setCursor(0,0);
- lcd.print("Berhasil ");
- lcd.setCursor(0,1);
- lcd.print("diperbaharui");
- for(int i=1; i<=3; i++){
- lcd.setCursor(i+11,1);
- lcd.print(".");
- delay(700);
- baca = EEPROM.read(3);
- Serial.println(baca);
- }
- //cekisi();
- //mode1=false;
- /*lcd.clear();
- delay(2000);
- //dtTombol = saldoSkrg;
- lcd.setCursor(0,1);
- lcd.print(saldoSkrg);
- //mode1=false;
- */
- return;
- }
- if(customKey=='*'){
- dtTombol=(dtTombol-dtTombol%10)/10;
- lcd.setCursor(0,1);
- lcd.print(" ");
- }
- }
- }
- void cekisi(){
- lcd.clear();
- delay(1000);
- baca = EEPROM.read(3);
- lcd.setCursor(0,1);
- lcd.print(baca);
- }
- void cekKartu(){
- if ( ! mfrc522.PICC_IsNewCardPresent()){
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial()){
- return;
- }
- lcd.clear();
- lcd.setCursor(0,1);
- lcd.print("Card uid:");
- dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
- }
- void dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- }
- }
- /*
- void isi(){
- lcd.setCursor(0,0);
- lcd.print("Input Password");
- customKey = customKeypad.getKey();
- /*
- if(customKey >= '0' && customKey <= '9')
- {
- passwd = passwd * 10 + (customKey - '0');
- lcd.setCursor(0,1);
- lcd.print(passwd);
- }
- if((customKey == 'D')&&(passwd == 112233)){
- lcd.clear();
- delay(1000);
- customKey == ' ';
- return;
- }
- if(customKey == 'C'){
- lcd.clear();
- delay(200);
- passwd = 0;
- }
- isi();
- }*/
- /*
- void isiscan(){
- lcd.setCursor(0,0);
- lcd.print("Scan Kartu");
- SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- // Serial.println("Put your card to the reader...");
- // Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent())
- {
- //return;
- }
- // Select one of the cards
- if ( ! mfrc522.PICC_ReadCardSerial())
- {
- //return;
- }
- //Show UID on serial monitor
- //lcd.setCursor(0,0);
- // Serial.print("UID tag :");
- String content= "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++)
- {
- // Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- // Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- content.toUpperCase();
- if (content.substring(1) == "03 3D 9E 02")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 1;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "99 AD B5 55")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 2;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "A3 32 48 83")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 3;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "06 5D 01 FA")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 4;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- isiscan();
- }
- */
- void cekTombol(){
- lcd.setCursor(0,0);
- lcd.print("Mau isi berapa");
- if(customKey!='A' && customKey!='B' && customKey!='C' && customKey!='#'){
- if(customKey=='*'){
- dtTombol=(dtTombol-dtTombol%10)/10;
- lcd.setCursor(0,1);
- lcd.print(" ");
- }else{
- dtTombol=dtTombol*10+customKey;
- }
- // lcd.setCursor(0,0);
- // lcd.print(str);
- lcd.setCursor(0,1);
- lcd.print(dtTombol);
- }
- /*SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- // Serial.println("Put your card to the reader...");
- // Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent())
- {
- return;
- }
- // Select one of the cards
- if ( ! mfrc522.PICC_ReadCardSerial())
- {
- return;
- }
- //Show UID on serial monitor
- //lcd.setCursor(0,0);
- // Serial.print("UID tag :");
- String content= "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++)
- {
- // Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- // Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- content.toUpperCase();
- if (content.substring(1) == "03 3D 9E 02")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 1;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "99 AD B5 55")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 2;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "A3 32 48 83")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 3;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- if (content.substring(1) == "06 5D 01 FA")
- {
- lcd.setCursor(0,1);
- lcd.print(content.substring(1));
- delay(3000);
- id = 4;
- lcd.clear();
- content.substring(1) = "";
- return;
- }
- */
- cekTombol();
- }
- void scan(){
- lcd.setCursor(0,0);
- lcd.print("Isi Berapa mL?");
- customKey = customKeypad.getKey();
- while(notif){
- if(customKey >= '0' && customKey <= '9')
- {
- isiku = isiku * 10 + (customKey - '0');
- lcd.setCursor(0,1);
- lcd.print(isiku);
- }
- digit = isiku;
- isiku *= 1000;
- Serial.print("saldo yang di input : ");
- Serial.println(isiku);
- Serial.println("Silahkan tap kartu untuk menambah saldo kartu");
- }
- if(customKey == 'C'){
- lcd.clear();
- delay(200);
- isiku = 0;
- }
- if((customKey == 'D')&&(id == 1)){
- lcd.clear();
- delay(2000);
- kartu1 = isiku;
- return;
- }
- if((customKey == 'D')&&(id == 2)){
- lcd.clear();
- delay(2000);
- kartu2 = isiku;
- return;
- }
- if((customKey == 'D')&&(id == 3)){
- lcd.clear();
- delay(2000);
- kartu3 = isiku;
- return;
- }
- if((customKey == 'D')&&(id == 4)){
- lcd.clear();
- delay(2000);
- kartu4 = isiku;
- return;
- }
- scan();
- }
- void bayar(){
- lcd.setCursor(0,0);
- lcd.print("Beli Berapa mL ?");
- customKey = customKeypad.getKey();
- if(customKey >= '0' && customKey <= '9')
- {
- beli = beli * 10 + (customKey - '0');
- lcd.setCursor(0,1);
- lcd.print(beli);
- }
- if(customKey == 'C'){
- lcd.clear();
- delay(200);
- beli = 0;
- }
- if((customKey == 'D')&&(id == 1)){
- lcd.clear();
- delay(2000);
- kartu1 = kartu1 - beli;
- if(kartu1 >= 0){
- Serial.println(id);
- Serial.println(beli);
- Serial.println(kartu1);
- delay(1000);
- lcd.setCursor(0,0);
- lcd.print("BERHASIL");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu1);
- delay(5000);
- lcd.clear();
- return;
- }
- if(kartu1 < 0){
- kartu1 = kartu1 + beli;
- lcd.setCursor(0,0);
- lcd.print("SALDO KURANG");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu1);
- delay(5000);
- lcd.clear();
- beli = 0;
- }
- }
- if((customKey == 'D')&&(id == 2)){
- lcd.clear();
- delay(2000);
- kartu2 = kartu2 - beli;
- if(kartu2 >= 0){
- Serial.println(id);
- Serial.println(beli);
- Serial.println(kartu2);
- delay(1000);
- lcd.setCursor(0,0);
- lcd.print("BERHASIL");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu2);
- delay(5000);
- lcd.clear();
- return;
- }
- if(kartu2 < 0){
- kartu2 = kartu2 + beli;
- lcd.setCursor(0,0);
- lcd.print("SALDO KURANG");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu2);
- delay(5000);
- lcd.clear();
- beli = 0;
- }
- }
- if((customKey == 'D')&&(id == 3)){
- lcd.clear();
- delay(2000);
- kartu3 = kartu3 - beli;
- if(kartu3 >= 0){
- Serial.println(id);
- Serial.println(beli);
- Serial.println(kartu3);
- delay(1000);
- lcd.setCursor(0,0);
- lcd.print("BERHASIL");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu3);
- delay(5000);
- lcd.clear();
- return;
- }
- if(kartu3 < 0){
- kartu3 = kartu3 + beli;
- lcd.setCursor(0,0);
- lcd.print("SALDO KURANG");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu3);
- delay(5000);
- lcd.clear();
- beli = 0;
- }
- }
- if((customKey == 'D')&&(id == 4)){
- lcd.clear();
- delay(2000);
- kartu4 = kartu4 - beli;
- if(kartu4 >= 0){
- Serial.println(id);
- Serial.println(beli);
- Serial.println(kartu4);
- delay(1000);
- lcd.setCursor(0,0);
- lcd.print("BERHASIL");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu4);
- delay(5000);
- lcd.clear();
- return;
- }
- if(kartu4 < 0){
- kartu4 = kartu4 + beli;
- lcd.setCursor(0,0);
- lcd.print("SALDO KURANG");
- lcd.setCursor(0,1);
- lcd.print("SALDO=");
- lcd.print(kartu4);
- delay(5000);
- lcd.clear();
- beli = 0;
- }
- }
- bayar();
- }
Add Comment
Please, Sign In to add comment