Hey I'm making a basic midi controller for my friend's intallation and I have a few questions.
First, I'll show you guys the sketch and the code I've made so far:
(sketches might be attached on below of this article!)
int switchPin1 = A0;
int midi = 1;
char note1 = 60; //C
char note2 = 62; //D
int switchState1 = LOW;
int currentSwitchState1 = LOW;
void setup() {
pinMode(switchPin1, INPUT);
pinMode(midi,OUTPUT);
Serial.begin(31250);
}
void loop() {
int pitch = analogRead(0);
currentSwitchState1 = digitalRead(switchPin1);
if( currentSwitchState1 == LOW && switchState1 == HIGH ) // push
noteOn(0x90, note1, 0x45);
delay(100);
if( currentSwitchState1 == HIGH && switchState1 == LOW ) // release
noteOn(0x90, note2, 0x45);
delay(100);
switchState1 = currentSwitchState1;
}
void noteOn(char cmd, char pitch, char velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
We're trying to play music automatically in ableton live when we touch the sensors.
We'll map midi keys with Play button to middle C(note1) and Pause button to D(note2)
So, we're trying to make the musics play when someone's touching installation and goes off when they take their hands off.
the question starts:
-
is it possible to gather 3 FSRs in one analog input and make them to work as one sensor with the sketch and the code that I've made??
-
currentswitchstate and switchstate starts in LOW status. and then be goes to high status. Do you guys know any solution to make analog sensors work in digital way? For example, if we set analog sensor state to "0~1023", like analoginoutserial, I want to make it digitally on in its 100 status and goes off for below of that. i would really be perfect to understand the solution if anyone knows how to solve it in map.
-
when the digital status of this sensor goes HIGH from LOW, it'll start to work as middle C note. but I want it to stop automatically after 100 miliseconds so I can make the play button to work clearly. Also, when his sensor goes LOW from HIGH, it'll work as middle D note, and automatically stop after milliseconds. But that does not mean the program's gonna ignore the energy what sensor's getting, right? How can I make it automatically stop? is it OK to just use delay(100);?
-
if anything looks weird in midi codes, please point it out. I'll love you guys for just reading this long post. thank you!