I've did some small Arduino project few years ago and have recently programmed a bit in Python but I'd say I'm a beginner at programming. Now however I'd like to pick up Arduino again for some music projects and the first project I'm aiming for is a voltage quantizer. Basically it should:
- Read a volatage on an analog input.
- Quantize the value to the nearest value in an array.
- Output the quantized value to a DAC.
Reading the input value is not to hard and outputting the value using a MCP4921 should probably be fine too, but I'm not entirely sure how to actually quantize the value.
So in the end I want to have a few different arrays to quantize against but, the first step would be to quantize it to 61 evenly distributed values. Here I'm thinking I could simply read the input value, divide it by the range (1024?), multiply it by 60, and rounding it to the closest integer using the math.h function round(). This value could than be divided by 60 and multiplied by the range of the DAC and directly outputted as a crude quantized value. Would you consider this a bad idea or can you suggest improvements?
My idea further was to compare this rounded value to the values of one of the arrays to find the closest value. Here I'm unsure how to proceed. Do you have suggestions?