I'm having a little problem and I'm hoping someone can help!
What I'm trying to do is create an electric melodeon (like an accordion). I need to take a pressure value from between a set of bellows (which I have done) and compare it to an atmospheric pressure value (which I also have done).
Then I want to create a MIDI note depending on this pressure value. Essentially, if a button is being pressed, I want one note if the pressure value is lower than the last pressure value, and another different note if it's higher.
I'm having trouble getting my Arduino to remember the previous pressure value. Is there a technique to achieve this?
Here's my code [there are also bits of code for a key matrix, but ignore them ]:
int analogValue1 = 0; // value read from the pot
int differenceBob = 0;
int oldBob = 0;
int Bob = 0;
void setup() {
Serial.begin(31250); // opens serial port, sets data rate to 9600 bps
pinMode(1, OUTPUT); //
pinMode(2, OUTPUT); //
pinMode(3, OUTPUT); //
pinMode(4, OUTPUT); //
pinMode(5, OUTPUT); //
pinMode(6, OUTPUT); //
pinMode(7, INPUT); //
pinMode(8, INPUT); //
pinMode(9, INPUT); //
pinMode(10, INPUT); //
pinMode(11, INPUT); //
pinMode(12, INPUT); //
}
void loop() {
Bob = analogRead(A0) / 6;
oldBob = Bob;
delay (10);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(5);
if (Bob < oldBob); {
if (digitalRead(7) == HIGH) {
SendMidi (0x90, 40, Bob);
}
if (digitalRead(7) == LOW) {
SendMidi (0x80, 0x18, Bob);
}}
if (Bob > oldBob); {
if (digitalRead(7) == HIGH) {
SendMidi (0x90, 45, Bob);
}
if (digitalRead(7) == LOW) {
SendMidi (0x80, 0x18, Bob);
}}
}
void SendMidi (int cmd, int value, int vel) {
Serial.write (cmd);
Serial.write (value);
Serial.write (vel);
}