Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- E E P R O M
- A R D U I N O
- */
- #include <EEPROM.h>
- #define ep_limit 30 // change mo to para mataasan limit. 5 = (5 x 255) = 1275 (vouchers)
- int epDigits = 0;
- int epAddress = 10;
- void setup() {
- // put your setup code here, to run once:
- epDigits = ep_read(epAddress);
- Serial.begin(9600);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- epDigits++;
- ep_write(epAddress, epDigits);
- Serial.println(epDigits);
- delay(1000);
- }
- void ep_write(int add, const int val)
- {
- int v = val;
- unsigned int i;
- for (i = 0; i < ep_limit; i++) {
- if (255 < v) {
- v = v - 255;
- EEPROM.write(add, 255);
- } else {
- EEPROM.write(add, v);
- v = 0;
- }
- add++;
- }
- }
- int ep_read(int add)
- {
- unsigned int v = 0;
- unsigned int i;
- for (i = 0; i < ep_limit; i++)
- {
- v = v + EEPROM.read(add);
- add++;
- }
- return v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement