Alternative musical instrument user interfaces can make use of various electronic components. Buttons, switches, keys, etc. are mostly likely "digital" interfaces - they are either on or off.
"Analog" interfaces can provide multiple values based on mechanical position or other physical property (temperature, pressure, magnetic field, ...)
A simple analog component is a potentiometer.
Let's look at this tutorial: https://www.electronicshub.org/how-potentiometer-works/
The potentiometer on your kit may or not be connected. Refer to Kit for the required connections.
It may be a linear or rotary potentiometer; they have the same connections:
Linear:
VCC to the "+" rail on the breadboard
GND to the "-" rail
DTB to pin A0 on the Pro Micro
Rotary:
Rightmost to the "+" rail on the breadboard
Leftmost to the "-" rail
Middle to pin A0 on the Pro Micro
In the Arduino IDE
File > Examples > Built-in examples > 0.1 Basics > ReadAnalogVoltage
(Or, you can copy/paste the code below into a new sketch (File > New, select all, delete)
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadAnalogVoltage
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
Sketch > Upload
Tools > Serial Monitor
Set the "baud rate" in the Serial Monitor to 9600
Move the potentiometer's knob and notice how the value changes.
You can also use Tools > Serial Plotter to display a graph of the value vs. time.
Note that other components that output an analog voltage can replace the potentiometer in this example.
Download this sketch: MIDI_pot_note_ProMicro.ino
Open it in the Arduino IDE, Sketch > Upload
This sketch adds the potentiometer to the MIDI_keys_ProMicro.ino sketch we've already seen.
The potentiometer position selects the MIDI note and the 3 buttons send that note in different octaves.
Easy to do this -- adding 12 to the note value raises it by an octave (doubles the frequency):
sendNoteOn(controller+12, MIDI_CHANNEL1);
Using your DAW or the Online MIDI Editor, try to play a song using the potetiometer and 3 buttons. Challenging?
Change the buttons to send MIDI on 3 different channels:
Change this code for each of the 3 buttons, using MIDI_CHANNEL1, MIDI_CHANNEL2, MIDI_CHANNEL3
sendNoteOn(controller, MIDI_CHANNEL1);
Using your DAW or the Online MIDI Editor, create 3 tracks and assign them to MIDI channels 1, 2, and 3. Use different instruments/sounds for each of the tracks.
In Signal (https://signal.vercel.app/), add two more tracks, change their instruments and MIDI channels to 2 and 3.
Experiment with the buttons and the potentiometer.
Your ideas?
Can you think of some creative way to use the potentiometer and buttons to create a different user interface?
Perhaps limit the selected notes to a specific scale? Other ideas?
Do some Arduino coding and create something new.
If you are just learning Arduino, collaborate with someone at the workshop with more experience.