// Example of Arduino feeding S2MIDI CC messages
int midiChannel = 9;
int outPin = 13; // the number of the output pin
int analogPin = 5;
// Analog smoothing stuff
int lastAnalog = 0;
int analogSmooth = 2; // Amount of change needed to send control change
unsigned char status;
void setup()
{
Serial.begin(38400);
}
void loop()
{
int reading = 0;
// Do analog line
reading = analogRead(analogPin)/8; // change 0-1024 into 0-127
if (abs(reading-lastAnalog) > analogSmooth) {
lastAnalog = reading;
// controlChange(midiChannel,10,127); // Send CC10
MIDI_TX(144,52,reading+30);
}
}
// Send a MIDI control change
void controlChange(byte channel, byte controller, byte value) {
midiMsg(channel+0xB0, controller, value);
}
// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
digitalWrite(outPin,HIGH); // indicate we're sending MIDI data
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
digitalWrite(outPin,LOW);
}
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
status = MESSAGE + midiChannel;
Serial.print(status);
Serial.print(PITCH);
Serial.print(VELOCITY);
}
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder