So, I tried out your sketch on an Arduino UNO r3. I made the change I suggested earlier regarding byte rather than integer types.
Since I was using the rugged circuits MIDI sheild, you will also see some extra lines which enable MIDI.
To make monitoring easier, I added a delay in the main loop.
Connection was to the MIDI-in on my audio interface (PreSonus AudioBox 44VSL). Monitoring was with MIDI-OX
// from arduino forum
// http://arduino.cc/forum/index.php/topic,122378.msg946983.html#msg946983
// modified to change variables from int to byte,
// using rugged circuits MIDI shield
#include <MIDI.h>
// MIDI enable pin, avoids conflict of Serial between USB for programming and DIN MIDI I/O
#define MIDI_ENABLE 12
// Variables:
byte cc = 0;
int AnalogValue = 0; // define variables for the controller data
byte lastAnalogValue = 0; // define the "lastValue" variables
void setup() {
// enable MIDI
pinMode(MIDI_ENABLE, OUTPUT);
digitalWrite(MIDI_ENABLE, HIGH);
// launch MIDI
MIDI.begin();
}
void loop() {
AnalogValue = analogRead(0);
// convert to a range from 0 to 127:
cc = AnalogValue/8;
// check if analog input has changed
if (lastAnalogValue != cc) {
MIDI.sendControlChange(16,cc,1);
// update lastAnalogValue variable
lastAnalogValue = cc;
} // endif
delay(500);
}
Results were as expected, I got all values between 0 and 127 inclusive over the range of travel of the pot. I used a 10-turn 1/4W wirewound 10k linear pot. Monitoring for several minutes did not reveal any erratic readings.
Looking at page 2 of the schematic shows a similar output circuitry to the MMA reference one - a couple of inverters and a 240R resistor.