Easily save and load combinations to permanent memory.
This library works with the built-in EEPROM that some Arduino AVR based borads have. An EEPROM is a type of non-volatile memory. This means that data can be permanently and can survive even when the power is off, just like a hard drive.
Arduino AVR boards have different EEPROM sizes. E.g.
Duemilanove: 512 bytes (ATmega168)
Uno: 1024 bytes (ATmega328)
Mega: 4096 bytes (ATmega1280 and ATmega2560)
Option 1. Download as ZIP and extract it into your libraries directory
Option 2. Clone this repository into your libraries directory
git clone https://github.com/wceballos/Combination_Arduino_Library.git
Option 3. Read this guide
https://www.arduino.cc/en/guide/libraries
A combination is instantiated using the following form:
Combination myCombination(length, eepromAddress = 0)
Parameters:
length: The number of elements in the combination.
eepromAddress: The EEPROM memory address where the combination is stored.
// Create a combination of 10 characters at the default address
Combination<char> combo1(10);
// Create a combination of 5 integers at addresss 20
Combination<int> combo2(5, 20);
// combo1 and combo2 do not overlap in memory, so they can be used simultaneously
The load() function allows loading a combination from memory into an array.
const int SIZE = 5;
// Create combination of integers
Combination<int> myCombo(SIZE);
// Load combination into a buffer
int buf[SIZE];
myCombo.load(buf);
The save() function allows storing an array into memory.
const int SIZE = 5;
// Create combination of integers
Combination<int> myCombo(SIZE);
// Load combination into a buffer
int buf[SIZE] = {5, 9, 7, 2, 3};
myCombo.save(buf);
The equals() function facilitates comparing user input to a stored combination.
const int SIZE = 5;
int userInput[SIZE] = {1, 1, 2, 3, 4};
// Create combination of integers
Combination<int> myCombo(SIZE);
// Assuming the combination has been stored prior
// Compares userInput to myCombo element by element. Returns true if they match.
bool isCorrect = myCombo.equals(userInput);
See examples directory for example programs.
This library is licensed under the GNU Lesser General Public License v3.0 See the LICENSE.txt file.