Showing posts with label github. Show all posts
Showing posts with label github. Show all posts

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: https://github.com/little-scale/readChange

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: 

#include

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: 

pot1.update(); 

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. 

pot1.change(); 

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

pot1.read(); 




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




Sunday, March 26, 2017

Mtof Library for Arduino

The mtof library for Arduino converts MIDI pitch values to frequency values and vice versa.

Usage is via two functions: mtof.toFrequency(pitch), which returns the frequency of an input pitch, and mtof.toPitch(frequency), which returns the MIDI note number of an input frequency.

All calculations are done as double floats.

Download the library and examples here: https://github.com/little-scale/mtof




Saturday, March 25, 2017

Log2 Library for Arduino

The math.h library for Arduino does not include a log2 function. The log2 library is an Arduino library for using logarithmic calculations with a base of 2.

The usage is straightforward: log2(value) returns a double float of log2 of the input value.

Download the library and examples here: https://github.com/little-scale/log2

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

The example sketch, shown below, returns 1000 Hz as a MIDI note value in the serial monitor.