I currently work on my first project - a midi controller. I need to read inputs from 8 potentiometers, 8 piezo buzzers and a couple of buttons. For that sake I used 2 multiplexers each one for pot or buzzers.
Potentiometers are meant to send a values to control sound parameters (volume), buzzers are for generating midi signal (each one is up to different midi note) with some velocity.
My problem is:
- I get inputs (changes of velocity) when I don't change the potentiometer's resistance. How can I make it stop sending all the same input?
- I can only read inputs from 1 analog pin (from 1 multiplexer). How can I read inputs from both multiplexers?
- When I hit one piezo, arduino sends a midi note with a proper velocity and not proper midi note (I'm hitting all the same piezo and it sends note 60, vel 30, note 64 vel 50). Maybe that's because I connected only one piezo to mux and grounded other mux inputs by 1m ohm resistors.
- Is there any way to express functioning of piezos (sending midi notes and velocities) and pots (sending only velocity value) in one function? If no, how can I adjust different parts of code to a different pins?
I use a clone of arduino uno (ch340g).
#define OUT_A 2
#define OUT_B 3
#define OUT_C 4
int lastVal = 0;
int piezo[8];
byte note[8] = {
57,58,59,60,61,62,63,64};
int pin;
int noteOn = 144;
int noteOff = 128;
int knock;
int threshold = 50;
boolean firstKnock;
int LED1 = 13;
void setup() {
pinMode(OUT_A, OUTPUT);
pinMode(OUT_B, OUTPUT);
pinMode(OUT_C, OUTPUT);
pinMode(LED1,OUTPUT);
Serial.begin(57600);
}
void loop() {
for (int i = 0b000; i <= 0b111; i++) {
digitalWrite(OUT_A, bitRead(i, 0));
digitalWrite(OUT_B, bitRead(i, 1));
digitalWrite(OUT_C, bitRead(i, 2));
knock = analogRead(piezo[i]);
if (knock>threshold){
knock = (knock/8) - 1;
byte node = note[i];
MIDImessage(noteOn, node, knock);
delay(50);
MIDImessage(noteOn, node, knock);
delay(20);
}
};
};
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
};