So I'm making a small piano project (with or without Mozzi library) using Arduino UNO or Pro Mini for the class (as a part of STEM education we are having here), but I have encountered some issues:
- I can't figure out how to read 13 keys (single octave C~B, and black keys) without freezing the tone every time key is being read or restarting the waveform each time the function is called.
- Using resistor array worked, but its tone drifted too much for the kit and it only allowed one tone to play even with multi-key polyphony code. Now I divided the button into four sections shown below (in image) to try to minimize pitch drift, but now I have to read 4 analog input (or 3 if I omit second octave C and don't use 13th button)
- Since Arduino's built-in Tone function only has single tone and there is no way around it (and you know how awful single tone synth sounds when it outputs pure PWM straight into that tiny Mylar speaker), we attempted to use Mozzi because it supports FM and sine output through PWM (and some LP filter if it's absolutely necessary), a sound synthesis library. But then I have to rewrite the entire code. (The code I used is lifted straight from https://www.arduino.cc/en/Tutorial/toneKeyboard) Could somebody help me a bit? It does not have to sound absolutely beautiful (basic waveforms are just fine) and it just has to have at least two-note polyphony.
Any help is appreciated!
p.s. Values of resistors on buttons (except for pull-down resistors) are placeholders.
Actual values from left to right on each row are: 4.7K, 1K, 470R, 100R