Hi there everyone, i'm trying to send a message trough TX serial ouput. the two codes i got for my project are this ones.
void setup()
{
Serial.begin(31250); // Default speed of MIDI serial port
pinMode(13, OUTPUT); // Light LED on pin 13 to notify of readynes
digitalWrite(13, HIGH);
}
int iAn0Val, iAn1Val, iAn2Val, iAn3Val, iAn4Val, iAn5Val, iAn6Val, iAn7Val, iAn8Val;
void loop()
{
//Slider 1
int iAn0ValPrev = iAn0Val; //Get the previous value of slider 1
iAn0Val = analogRead(0)/8;
analogPinMidiTX(1,iAn0Val,iAn0ValPrev); //TX the value of slider 1
//Slider 2
int iAn1ValPrev = iAn1Val; //Get the previous value of slider 2
iAn1Val = analogRead(1)/8;
analogPinMidiTX(2,iAn1Val,iAn1ValPrev); //TX the value of slider 2
//Slider 3
int iAn2ValPrev = iAn2Val; //Get the previous value of slider 3
iAn2Val = analogRead(2)/8;
analogPinMidiTX(3,iAn2Val,iAn2ValPrev); //TX the value of slider 3
//Slider 4
int iAn3ValPrev = iAn3Val; //Get the previous value of slider 4
iAn3Val = analogRead(3)/8;
analogPinMidiTX(4,iAn3Val,iAn3ValPrev); //TX the value of slider 4
//Slider 5
int iAn4ValPrev = iAn4Val; //Get the previous value of slider 5
iAn4Val = analogRead(4)/8;
analogPinMidiTX(5,iAn4Val,iAn4ValPrev); //TX the value of slider 5
//Slider 6
int iAn5ValPrev = iAn5Val; //Get the previous value of slider 6
iAn5Val = analogRead(5)/8;
analogPinMidiTX(6,iAn5Val,iAn5ValPrev); //TX the value of slider 6
//Slider 7
int iAn6ValPrev = iAn6Val; //Get the previous value of slider 7
iAn6Val = analogRead(6)/8;
analogPinMidiTX(7,iAn6Val,iAn6ValPrev); //TX the value of slider 7
//Slider 8
int iAn7ValPrev = iAn7Val; //Get the previous value of slider 8
iAn7Val = analogRead(7)/8;
analogPinMidiTX(8,iAn7Val,iAn7ValPrev); //TX the value of slider 8
}
void analogPinMidiTX(int iChan, int iVal, int iValPrev)
{
//only TX the value over midi if it is changed, as to prevent spamming the midi port and thus confusing the receiving application in learning mode
if(iValPrev != iVal)
{
MidiTX(176,iChan,iVal);
}
}
void MidiTX(unsigned char MESSAGE, unsigned char CONTROL, unsigned char VALUE) //pass values out through standard Midi Command
{
Serial.print(MESSAGE);
Serial.print(CONTROL);
Serial.print(VALUE);
}
at this time i am able to send the value of a 4K7 potentiometer over midi to control Pan in Logic Pro 9, but now i have 8 buttons (bang tipe not trigger) and i want to send the message in the same way, but at the sime time i want this bang buttons to be trigger so that when i press 1 time it gives high and it stay HIGH, and only get's LOW when i press again.
Here is the Code i have for the digital button read.
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Thanks in Advance