Giter VIP home page Giter VIP logo

combination_arduino_library's Introduction

Combination Arduino Library

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)  

Installing

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

Usage

Creating combination instance

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.

Example code

// 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

Loading a saved combination

The load() function allows loading a combination from memory into an array.

Example code

const int SIZE = 5;

// Create combination of integers
Combination<int> myCombo(SIZE);

// Load combination into a buffer
int buf[SIZE];
myCombo.load(buf);

Saving a combination to memory

The save() function allows storing an array into memory.

Example code

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);

Comparing user input to the stored combination

The equals() function facilitates comparing user input to a stored combination.

Example code

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.

License

This library is licensed under the GNU Lesser General Public License v3.0 See the LICENSE.txt file.

combination_arduino_library's People

Contributors

wceballos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.