Wednesday, March 29, 2017

readChange Library for Arduino

The readChange library for Arduino allows the user to read an analog input, and then detect and respond to change. 

Download the library with examples here:

To give an example of use - the value of a potentiometer connected to an analog input should be read, compared against a previously-read value. The data should be sent via a serial connection to the Arduino IDE Serial Monitor, but only when the value of the potentiometer has changed. 

To install this library, download the .zip file and move the decompressed folder to Documents/Arduino/libraries/.

The library can be used in a sketch by including it at the top of the code: 


The library contains a parameterised constructor called readChange, which can be used to create instances of objects by name. When creating the instance, the readChange constructor takes one argument, which is the analog input pin that should be attached. 

For example, placing the following line before setup() will create a new readChange object named "pot1", which will read the input of analog input pin 0:

readChange pot1(0);

Each readChange object can then use three functions - update(), change() and read(). 

The update() function should be called regularly - for example, once every loop(). This will update the readChange instance by reading the current value from the analog input pin that was attached during instance creation: 


If the value of the analog input has changed, then the change() function will return true. Used in conjunction with an if statement, this can be used to detect and respond to changes in the analog input value. 


The read() function will return the current value of the analog input.; 

In the context of an example, the above functions could be used as follows: