How i assign rx.byte3 to integer value

Hello i'm trying to make presonus faderport with arduino i'm receiving fader position data from Studio One but i can't assing to integer value how i assign to integer rx.byte3 value

Here is my code

#include <MIDIUSB.h>
#include <MIDIUSB_Defs.h>
#include <frequencyToNote.h>
#include <pitchToFrequency.h>
#include <pitchToNote.h>

int byte3;

/*

*Fevzi Kutay Sarigul FaderPort Test
 */ 


/*
 * MIDIUSB_test.ino
 *
 * Created: 4/6/2015 10:47:08 AM
 * Author: gurbrinder grewal
 * Modified by Arduino LLC (2015)
 */ 



// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).

void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

void setup() {
  Serial.begin(115200);
}

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}

void midiCommand(byte cmd, byte data1, byte  data2) {
  // First parameter is the event type (top 4 bits of the command byte).
  // Second parameter is command byte combined with the channel.
  // Third parameter is the first data byte
  // Fourth parameter second data byte

  midiEventPacket_t midiMsg = {cmd >> 4, cmd, data1, data2};
  MidiUSB.sendMIDI(midiMsg);
}

void loop() {
  //noteOn(0, 94, 127);   // Channel 0, 5. La# , tam velocity
  
  
 // Veri alma bolumu

  midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if (rx.header != 0) {
      Serial.print("Received: ");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, DEC);//Default olarak hex studio one da hex gonderiyor fakat midicommand icin ilk hane hex ikinci ve ucuncu hane decimal
      Serial.print("-");
      Serial.println(rx.byte3, DEC);//Default olarak hex studio one da hex gonderiyor fakat midicommand icin ilk hane hex ikinci ve ucuncu hane decimal
    }
  } while (rx.header != 0);


  

// Veri gonderme bolumu

 //MidiUSB.flush();
  delay(1000);



  midiCommand(0xE0,127,127); // Secili kanalin faderini son seviyeye getir
  midiCommand(0x90,94,127);  // Play tusu Channel 0 94Numaralı Nota 127 velocity
  //MIDI command icin flush kullanmaya gerek yok direkt olarak gonderiliyor triggerlanmali
  

  
}

I don't see any attempt in you code to assign the value to an integer. What did you try ?

Hello bob im trying to Im receiving midi bytes i want to rx.byte3 value to integer value for sending to midi command. I couldn't attempt because i don't know how i do

Serial.println(rx.byte3, DEC);

I want to assign rx.byte3 to integer value

i wrote midiCommand(0xE0,127,127) but i want midiCommand(0xE0,127,byte3) or midiCommand(0xE0,byte2,byte3)

In your sketch do you see the value that you want when you print rx.byte3 ?

Yes. When i touched button in DAW i receive midi command message for example
90-94-127 (Play Button) rx.byte 1-rx.byte2-rx.byte3

and i assign to third value to integer

If you can print the value what have you tried to assign it to a variable ? It should be a single line of code but I don't see it in your sketch

I tried to

midiEventPacket_t rx;
  do {
    rx = MidiUSB.read();
    if (rx.header != 0) {
      Serial.print("Received: ");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, DEC);//Default olarak hex studio one da hex gonderiyor fakat midicommand icin ilk hane hex ikinci ve ucuncu hane decimal
      Serial.print("-");
      Serial.println(rx.byte3, DEC);//Default olarak hex studio one da hex gonderiyor fakat midicommand icin ilk hane hex ikinci ve ucuncu hane decimal
rx.byte3 = byte3;
Serial.println(byte3)
    }
  } while (rx.header != 0);

but byte3 value is writing 0 continuously then i deleted the code and created topic in forum

Maybe you want byte3 = rx.byte3; ?

What do you see if you print rx.byte3, assign it to a variable then print the variable ?

      Serial.println(rx.byte3, DEC);
      byte byte3 = rx.byte3;
      Serial.println(byte3, DEC);

Solved thanks for help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.