Hello, i am trying to figure out how the trigger one
midiNote with a sensorReading, i would like to have one
note and not a lot of notes.
I modified two scetches but none is working the way i would like.
Scetch 2 changes the MIDInote according to the sensorvalue, but when i remove the delay it sends out
a midinote on every voidloop, so that's too much
I want one note with every change of the sensorReading
within the given parameters
Arpeggio
Scetch 1
const int sensorMin = 100; // sensor minimum, discovered through experiment
const int sensorMax = 500; // sensor maximum, discovered through experiment
void setup() {
// initialize serial communication:
Serial.begin(31200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // GND 0 Volt supply to opto-coupler
digitalWrite(2, HIGH);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
byte note = 0x1E;
// do something different depending on the
// range value:
switch (range) {
case 0: // your hand is on the sensor
noteOn(0x90, 0x2D, 0x45);
break;
case 1: // your hand is close to the sensor
noteOn(0x90, 0x30, 0x45);
break;
case 2: // your hand is a few inches from the sensor
noteOn(0x90, 0x34, 0x45);
break;
case 3: // your hand is nowhere near the sensor
noteOn(0x90, 0x39, 0x45);
break;
}
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.print(cmd, BYTE);
Serial.print(pitch, BYTE);
Serial.print(velocity, BYTE);
}
Scetch 2
const int sensorMin = 000; // sensor minimum, discovered through experiment
const int sensorMax = 1000; // sensor maximum, discovered through experiment
void setup() {
// initialize serial communication:
Serial.begin(31200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // GND 0 Volt supply to opto-coupler
digitalWrite(2, HIGH);
}
void loop() {
int sensorReading = analogRead(0);
if (sensorReading <= 400)
{noteOn(0x90, 0x3F, 0x45);
delay (400);
noteOn(0x90, 0x3F, 0x00);}
else if (sensorReading >= 100)
{noteOn(0x90, 0x2A, 0x45);
delay (400);
noteOn(0x90, 0x2A, 0x00);
}
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.print(cmd, BYTE);
Serial.print(pitch, BYTE);
Serial.print(velocity, BYTE);
}