

#Arduino simplesynth sketch update
I only update the wavetable and envelope if the potentiometer value actually changes. Any potentiometer not being scanned will keep its previous value so it can still be used in the calculations. In order to keep the updateControl() function running fairly quickly I only scan one potentiometer on every run of the function.

#define WAVT_PIN 0 // WavetableĮach potentiometer is scaled appropriately using bit-shifts when read (using the mozziAnalogRead function) to choose between the following ranges, and if any aren’t being used (i.e.


#Arduino simplesynth sketch code
So, by way of example, the following should mean that the code has reproduced the three-potentiometer sketch (using A0, A1 and A2) used in the Arduino FM MIDI Synthesis with Mozzi – Part 2. These defines double as specifying the analog pins (0=A0 through to 5=A5) to use for each function too. The following potentiometers are available and can be removed by commenting out the appropriate “#define” statements at the top of the sketch. It allows you to decide now many potentiometers to have wired into your board, allowing you to reproduce the two previous Mozzi projects if you wish. When it came to it, I ended up building it on proto board rather than stripboard and used the component legs to make the connections as can be seen below. If you build one yourself I expect your socket will be different to mine. Note that in the diagram below, the components should actually be seated on the underside of the board and I’ve represented my socket with two 4-pin female headers – but in reality it actually has four pins represented by the four ends of the two headers. Finally there are male header pins to allow the board to plug straight into the Arduino taking the signal from pin 9 and the GND from the same set of header pins. I also soldered a stereo jack socket to the stripboard too, which takes the signal and sends it to the two signal pins of a stereo jack as illustrated below. I’ve built up a simple Mozzi output low-pass filter, as detailed on the Mozzi site, consisting of a 270Ω resistor between pin 9 and the output jack and a 100nF capacitor between the signal and ground. The Arduino itself will require a MIDI input on the RX pin as usual and a sound output stage on pin 9. The above circuit has a 5V and GND connection to all six potentiometers and then six individual signal pins which will connect to the Arduino A0 to A5 analog inputs. This is an extension of the previous circuit, but as the number of controls increases it becomes worth committing it to stripboard – but it is still possible to build on solderless breadboard if you prefer.
