Deadp1xels
Well-known member
Code:
int muxPinA = 0;
int muxPinB= 1;
int muxPinC =2;
int muxPinD =3;
int analogReadPin(0);
const int midiChannel =1;
// Sets pot smoothing tolerances
int sensorTolerance =16;
int ccTolerance = 2;
int cAmount = 2; int cc4knob[2] = {61,62}; //CC1, CC2, CC3 ...
//example for 16 knobs:
//int cc4knob[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int ccValue[8]; // Value of the knob (MIDI CC range: [0,127]
int sensorValue[8]; // value from the analog input (Analogue Input range [0,1023])
// Sets inital values for bitReads
int r0 = 0;
int r1 = 0;
int r2 = 0;
int r3 = 0;
void setup()
{
pinMode(muxPinA, OUTPUT);
pinMode(muxPinB, OUTPUT);
pinMode(muxPinC, OUTPUT);
pinMode(muxPinD, OUTPUT);
pinMode (analogReadPin, INPUT);
Serial.begin(9600);
}
void loop()
{
for (int i = 0; i < cAmount; i++)
{
// Loads values into "r" variables
r0 = bitRead(i,0);
r1 = bitRead(i,1);
r2 = bitRead(i,2);
r3 = bitRead(i,3);
// Writes bits to each pin, based on "r"
digitalWrite(muxPinA, r0);
digitalWrite(muxPinB, r1);
digitalWrite(muxPinC, r2);
digitalWrite(muxPinD, r3);
int newSensorValue = analogRead(analogReadPin);
// Smoothing
if (abs(newSensorValue - sensorValue[i]) > sensorTolerance)
{
sensorValue[i] = newSensorValue;
int newCCValue = sensorValue[i] / 8; // Divides value by 8 for MIDI (0-127)
if (abs(newCCValue - ccValue[i]) > ccTolerance)
{
ccValue[i] = newCCValue;
usbMIDI.sendNoteOn(ccValue[i], newCCValue, midiChannel); // Sends USB MIDI
delay(10);
}
}
}
}
I'm navigating away from my button to play notes, and moving to piezos to allow for velocity aswell
I have my piezos wired in parrelel with a 1Mohm resistor positive going to input of a 74HC4076E Multiplexer
This is a piece of code i had and modified for a while ready for when i dove head first into multiplexing
Ideally i want 12 piezos playing one octave with velocity control
Currently the two piezos i have trigger the same note and are ULTRA sensitive, to the point they trigger a note 5-6 times a second at alternating velocity
Any ideas?
Last edited: