Wednesday, May 11, 2016

Final IV

Implementation

Code:

Coding this change box was really tricky only because I needed a persistent variable that could be written and accessed over multiple program runs.

Arduino has EEPROM memory which is writable and persistent, HOWEVER you can only store one byte of data at each EEPROM address.

I did a lot of research online and was playing around with some functions to splice and store data over several addresses when I found someone who had written the functions already.

----------
Full disclosure and Attribution:

I used the functions EEPROM_Write_Int and EEPROM_READ_Int

StackExchange Question: "How to Store 2 analogRead values and read using EEPROM for Arduino uno?"

Question Id: 15910 (http://arduino.stackexchange.com/questions/15910/how-to-store-2-analogread-values-and-read-using-eeprom-for-arduino-uno)

Author: Anurag S. Vasanwala (AnuragVasanwala@gmail.com)
----------

I needed to change one thing in the write function:

It turns out that EEPROM has a limited number of writes before the address wears out. I changed the final EEPROM.write() to EEPROM.update(), because .update() will only rewrite if the data is different saving memory

This problem also meant that I had to flag each sense of a coin from the photo interruptors and only update my EEPROM within a flagged if statement. If one ended up outside of an if statement I could burn through the address very quickly because of how many cycles the program can go through every second.

I then just printed the total on the LCD screen in my void loop() so that it updates in real time

The reset button simply saves zero to all the EEPROM addresses 

Code:






No comments:

Post a Comment