How do I send a MIDI message only when there is a change in the analog input?


hi,

i have project sends midi message relating tremolo depth amount read potentiometer connected analog input on arduino board. have managed sketch to  send midi messages, continue send, when there no change in value pot. have been trying, no success, send message when value changes.  have tried 'if' statements , 'eeprom.read' , 'write' functions compare current value previous , write when different doesn't seem work.

could please offer me advice. appreciated.
here project far:

code: [select]

#include <eeprom.h>
int sensorvalue=0;
int addr;
void setup() {
  //  set midi baud rate:
  serial.begin(31250);
 
}
void loop() {
    // read analogue input 0, divide 8, set sensorvalue
    sensorvalue = analogread(a0)/8;
   
    eeprom.write(addr, sensorvalue);
   
    addr = addr+1;
    if (addr ==512)
    addr=0;
   
    int sensorvaluenew = eeprom.read(addr);
   
    if (sensorvaluenew != sensorvalue){
    //write midi message:: control change channel 1 (0xb0), controller 92 (tremolo depth), value 20
    depthchange(0xb0, 0x5c, 127-sensorvalue);
     delay(200);
    }
   
  }
//write midi message
void depthchange(int cmd, int controller, byte value) {
  serial.write(cmd);
  serial.write(controller);
  serial.write(value);
}

ditch eeprom before harm arduino, 100k writes , eeprom die don't this.

after compare old value current value , updtae old current.

mark


Arduino Forum > Using Arduino > Programming Questions > How do I send a MIDI message only when there is a change in the analog input?


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support