@@ -166,8 +166,10 @@ int encoderWrite()
166
166
else
167
167
{
168
168
lcd.clear ();
169
- lcd.print (" New Balance :" );
169
+ lcd.print (" New balance :" );
170
+ lcd.setCursor (0 ,1 );
170
171
lcd.print (newPosition / 4 );
172
+
171
173
oldPosition = newPosition;
172
174
Serial.println (newPosition / 4 );
173
175
}
@@ -186,16 +188,14 @@ void nfc_write()
186
188
uint8_t currentblock; // Counter to keep track of which block we're on
187
189
bool authenticated = false ; // Flag to indicate if the sector is authenticated
188
190
uint8_t data[16 ] = {0x04 , 0x0A , 0x52 , 0x18 , 0x7B , 0x2C , 0x10 , 0x68 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x45 , 0x55 , 0x43 }; // Array to store block data during reads
189
- uint8_t savedData[16 ];
190
- int currentBalance = 0 ;
191
+ uint8_t savedData[16 ];
191
192
192
- int value = encoderWrite () * 100 ;
193
+ int newBalance = encoderWrite () * 100 ;
193
194
194
-
195
- Serial.print (" New value = " );Serial.println (value);
195
+ Serial.print (" New value = " );Serial.println (newBalance);
196
196
uint8_t balance[] = {0 , 0 };
197
- balance[0 ] = value / 256 ;
198
- balance[1 ] = value - (balance[0 ] * 256 );
197
+ balance[0 ] = newBalance / 256 ;
198
+ balance[1 ] = newBalance - (balance[0 ] * 256 );
199
199
Serial.print (" Hex 1 = " );Serial.println (balance[0 ], HEX);
200
200
Serial.print (" Hex 2 = " );Serial.println (balance[1 ], HEX);
201
201
digitalWrite (writeLedPin, HIGH);
@@ -206,8 +206,8 @@ void nfc_write()
206
206
207
207
success = nfc.readPassiveTargetID (PN532_MIFARE_ISO14443A, uid, &uidLength);
208
208
209
- if (success) {
210
- // Display some basic information about the card
209
+ if (success)
210
+ {
211
211
Serial.println (" Found an ISO14443A card" );
212
212
lcd.clear ();
213
213
lcd.print (" I Found a card !" );
@@ -267,8 +267,32 @@ void nfc_write()
267
267
}
268
268
else
269
269
{
270
- if (currentblock == 24 )
270
+ if (currentblock == 24 || currentblock == 26 )
271
271
{
272
+ nfc.mifareclassic_ReadDataBlock (currentblock, data);
273
+ data[6 ] = balance[0 ];
274
+ data[7 ] = balance[1 ];
275
+ success = nfc.mifareclassic_WriteDataBlock (currentblock, data);
276
+ if (success)
277
+ {
278
+ Serial.print (" Block " );Serial.print (currentblock, DEC);
279
+ if (currentblock < 10 )
280
+ {
281
+ Serial.print (" " );
282
+ }
283
+ else
284
+ {
285
+ Serial.print (" " );
286
+ }
287
+ nfc.PrintHexChar (data, 16 );
288
+
289
+ }
290
+ }
291
+ else if (currentblock == 25 )
292
+ {
293
+ nfc.mifareclassic_ReadDataBlock (currentblock, data);
294
+ data[5 ] = balance[0 ];
295
+ data[6 ] = balance[1 ];
272
296
success = nfc.mifareclassic_WriteDataBlock (currentblock, data);
273
297
if (success)
274
298
{
@@ -300,15 +324,12 @@ void nfc_write()
300
324
Serial.println (" Ooops ... this doesn't seem to be a Mifare Classic card!" );
301
325
}
302
326
}
303
- // Wait a bit before trying again
304
- // Serial.println(savedData[0], HEX);
305
- // Serial.println(savedData[1], HEX);
306
-
327
+
307
328
lcd.clear ();
308
- lcd.print (" Balance :" );
329
+ lcd.print (" New balance :" );
309
330
lcd.setCursor (0 ,1 );
310
- lcd.print (currentBalance );
311
- Serial.println (currentBalance , DEC);
331
+ lcd.print (newBalance / 100 );
332
+ Serial.println (newBalance , DEC);
312
333
Serial.println (" \n\n DONE ! waiting 4 the button" );
313
334
digitalWrite (writeLedPin, LOW);
314
335
wait4button ();
@@ -439,22 +460,17 @@ void nfc_read()
439
460
Serial.println (" Ooops ... this doesn't seem to be a Mifare Classic card!" );
440
461
}
441
462
}
442
- // Wait a bit before trying again
443
- // Serial.println(savedData[0], HEX);
444
- // Serial.println(savedData[1], HEX);
445
-
446
463
lcd.clear ();
447
464
lcd.print (" Balance :" );
448
465
lcd.setCursor (0 ,1 );
449
- lcd.print (currentBalance);
466
+ lcd.print (currentBalance / 100 );
450
467
Serial.println (currentBalance, DEC);
451
468
Serial.println (" \n\n DONE ! waiting 4 the button" );
452
469
digitalWrite (readLedPin, LOW);
453
470
wait4button ();
454
471
lcd.clear ();
455
472
Serial.print (" end read = " );Serial.println (oldPosition);
456
473
457
-
458
474
Serial.flush ();
459
475
}
460
476
0 commit comments