analog inputs

Unlike Digital Inputs which only transmit two values (On and Off, or High and Low), Analog Inputs are continuous sensors that send a range of values. Analog inputs are great for variable control of parameters like speed, volume, or saturation.  The pictures below show how to connect a potentiometer and a photocell, typical Analog Inputs. There are a ton of different types of analog inputs. Some of the more complicated sensors are difficult to connect and use over MIDI, but the majority of analog sensors will work. For more detail, see the Analog Input tutorial on the Teensy website (or search for any of the million arduino resources on the topic).

A potentiometer is a variable resistor that usually has three legs. Connect one outer leg to power and the other to ground. The middle leg connects to an Analog Input Pin, in this case A0. Here is the code for using an Analog input…

// Instantiate an array of CCPotentiometer objects that send 
// MIDI CC messages when an analog sensor is changed (0-127) 
CCPotentiometer potentiometers[]{ 
{ A0, 16}, // Analog pin (A0) connected to potentiometer, midi controller number (16) 
{ A1, 17}, // Analog pin (A1)connected to light dependant resistor (LDR), midi ontroller number (17)} 
};

Once again, we start by creating an object, this time it’s called CCPotentiometer and then we create a bunch of them by creating an array of potentiometers. Again, this initial code will stay the same, regardless of how many analog inputs you add! On the next line we specify a pin number, A0, and then tell the arduino what channel to send information on, in this case 16. So the arduino will send Midi control messages– a range of messages between 0-127, on channel 16.

The photocell does require a 10K resistor, which connects one of the legs to ground. The other leg is connected to  power  and the leg with the resistor is also connected to an Analog Input Pin, in this case A1. Now both of them together…