Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pls help me to add pitchbend and modulation wheel code #13

Open
dimitrios73gr opened this issue Mar 8, 2021 · 20 comments
Open

Pls help me to add pitchbend and modulation wheel code #13

dimitrios73gr opened this issue Mar 8, 2021 · 20 comments

Comments

@dimitrios73gr
Copy link

dimitrios73gr commented Mar 8, 2021

Hello,

your code is perfect and helped me to convert a velocity sensitive keyboard from an old casio ctk-691 to midi..The code is awesome and working 100%.
I want to add a pitch bend and a modulation wheel but i dont know the code to do that...
Please help me if you know..thanks in advance...

@andersonbruno02
Copy link

andersonbruno02 commented Mar 11, 2021

im working in the same thing.
we need use midi control change(CC) 1 for modulation wheel
https://www.noterepeat.com/articles/how-to/213-midi-basics-common-terms-explained
so we neeed figure out how send this control change message.
im considering use this library:
https://github.com/arduino-libraries/MIDIUSB/blob/master/examples/MIDIUSB_write/MIDIUSB_write.ino
https://github.com/silveirago/DIY-Midi-Controller/blob/master/Code%20-%20c%C3%B3digo/en-DIY_midi_controller/en-DIY_midi_controller.ino
i know it will became a rats nast but if works its fine for me

@andersonbruno02
Copy link

void send_midi_eventcc(byte status_byte, byte key_index, unsigned long time)
{
unsigned long t = time;
#ifdef DEBUG_MIDI_MESSAGE
char out[32];
sprintf(out, "%02X %02X %03d %d", status_byte, key_index, vel, t);
Serial.println(out);
#else
Serial.write(status_byte);
Serial.write(key_index);
Serial.write(t);
#endif
}
const int N_POTS = 1; //* número total de pots (slide e rotativo)
const int POT_ARDUINO_PIN[N_POTS] = {A0, A1}; //* pinos de cada pot conectado diretamente ao Arduino
int potCState[N_POTS] = {0}; // estado atual da porta analogica
int potPState[N_POTS] = {0}; // estado previo da porta analogica
int potVar = 0; // variacao entre o valor do estado previo e o atual da porta analogica
int midiCState[N_POTS] = {0}; // Estado atual do valor midi
int midiPState[N_POTS] = {0}; // Estado anterior do valor midi
const int TIMEOUT = 300; //* quantidade de tempo em que o potenciometro sera lido apos ultrapassar o varThreshold
const int varThreshold = 100; //* threshold para a variacao no sinal do potenciometro
boolean potMoving = true; // se o potenciometro esta se movendo
unsigned long PTime[N_POTS] = {0}; // tempo armazenado anteriormente
unsigned long timer[N_POTS] = {0}; // armazena o tempo que passou desde que o timer foi zerado

byte cc = 1; //* O mais baixo MIDI CC a ser usado
voidsetup

void loop
for (int i = 0; i < N_POTS; i++) { // Faz o loop de todos os potenciômetros

potCState[i] = analogRead(POT_ARDUINO_PIN[i]);

midiCState[i] = map(potCState[i], 450, 880, 0, 127); // Mapeia a leitura do potCState para um valor utilizável em midi

potVar = abs(potCState[i] - potPState[i]); // Calcula o valor absoluto entre a diferença entre o estado atual e o anterior do pot

if (potVar > varThreshold) { // Abre o portão se a variação do potenciômetro for maior que o limite (varThreshold)
  PTime[i] = millis(); // Armazena o tempo anterior
}

timer[i] = millis() - PTime[i]; // Reseta o timer 11000 - 11000 = 0ms

if (timer[i] < TIMEOUT) { // Se o timer for menor que o tempo máximo permitido, significa que o potenciômetro ainda está se movendo
  potMoving = true;
}
else {
  potMoving = false;
}

if (potMoving == true) { // Se o potenciômetro ainda estiver em movimento, envie control change
  if (midiPState[i] != midiCState[i]) {

     send_midi_eventcc(0xB0, cc+ i, midiCState[i]);

    potPState[i] = potCState[i]; // Armazena a leitura atual do potenciômetro para comparar com a próxima
    midiPState[i] = midiCState[i];
  }
}

}

@andersonbruno02
Copy link

try this its working for me

@andersonbruno02
Copy link

for pitch bend change to this
send_midi_eventcc(0xE0, cc+ i, midiCState[i]);

@dimitrios73gr
Copy link
Author

for pitch bend change to this
send_midi_eventcc(0xE0, cc+ i, midiCState[i]);

Thank you very very much for your help!!!!...I will try it soon and I will respense to you!!!...one last thing...the code you send me in which place of the original code i must add...I mean at wich line i must insert the code...Sorry for bothering you but i dont know much about programming...que tenga un lindo día...Gracias por tu ayuda

@andersonbruno02
Copy link

Check my fork, there you can see the code
https://github.com/andersonbruno02/keyboardscanner

@dimitrios73gr
Copy link
Author

for pitch bend change to this
send_midi_eventcc(0xE0, cc+ i, midiCState[i]);

Check my fork, there you can see the code
https://github.com/andersonbruno02/keyboardscanner

Perfect!!!!!....Thanks you very much for your fast response and your help....I will try it all together and I will tell you the results....

@dimitrios73gr
Copy link
Author

dimitrios73gr commented Mar 15, 2021

Hello,
Everything is working except PEDAL...I connect the one leg of push button on pin 21 and the other leg to gnd..Do I need to use resistor between pedal pin 21 (SCL MEGA2560) and ground?...not working at all..any other setting?...

also I see an error on code (see attached photo)
error

Thanks in advance

@godbless876
Copy link

godbless876 commented Mar 15, 2021 via email

@andersonbruno02
Copy link

andersonbruno02 commented Mar 16, 2021

yes you need use hairless and loop mid because my arduino dont have native usb port...
i think original arduino mega with custom firmeware can use usb native ports but also arduino leonardo and arduino due have native out of the box.
im not shure about teensy boards, but perhaps you can try make your own code with this:
https://github.com/silveirago/DIY-Midi-Controller/blob/master/Code%20-%20c%C3%B3digo/en-DIY_midi_controller/en-DIY_midi_controller.ino

@andersonbruno02
Copy link

about the pedal just delete this error line
byte pedal = LOW;
im ajusting this on my code as well. thanks!

@andersonbruno02
Copy link

also theres a better way to use the pedal.
using the midi control change
i will be implementing this very soon

@dimitrios73gr
Copy link
Author

dimitrios73gr commented Mar 17, 2021

also theres a better way to use the pedal.
using the midi control change
i will be implementing this very soon

Hello,sorry for bothering you again...Pedal is not working at all....(MEGA 2560,DIO2 1.5.1I... connect one wire from button to pin21 (SCL) and the other button cable to arduino gnd without any resistor...is this correct?...Do I need any wire from switch to 5V?

@andersonbruno02
Copy link

try the new code:
https://github.com/andersonbruno02/keyboardscanner is control change now.
im using the internal pullup resistor from arduino, no need add more resistors.
only a conection to the pin and ground you also can try change the port see if makes diference

@dimitrios73gr
Copy link
Author

try the new code:
https://github.com/andersonbruno02/keyboardscanner is control change now.
im using the internal pullup resistor from arduino, no need add more resistors.
only a conection to the pin and ground you also can try change the port see if makes diference

THANKS THANKS!!!!...Its working!!!!...Now I can start my project..A mini atx pc inside my broken casio ctk-651 with usb audio midi soundcard so I can create a synth and sampler with vsti etc...thenks alo for your help...

@gandrim
Copy link

gandrim commented Jan 28, 2022

coba kode baru: https://github.com/andersonbruno02/keyboardscanner adalah perubahan kontrol sekarang. im menggunakan resistor pullup internal dari arduino, tidak perlu menambahkan lebih banyak resistor. hanya koneksi ke pin dan ground Anda juga dapat mencoba mengubah port, lihat apakah ada bedanya

Periksa garpu saya, di sana Anda dapat melihat kode https://github.com/andersonbruno02/keyboardscanner

hi anderson can you help me ... i have a roland em 20 keyboard ... i want to convert it to a midi controller ... i have tried to make it but it doesn't work, the problem is roland em 20 has 2 16x16 bands,, i have succeeded in making the first ribbon but when i try for the 2nd ribbon it makes everything random.. can you help me

@efendi1886
Copy link

hi...
I've seen the code on this page, but I don't see or read which pins will be used for the keyboard keys, so I'm still confused, which pins to use???
can anyone give me help me here???

@efendi1886
Copy link

I have a broken Roland 61 key keyboard, I want to make it a midi controller, can I use the code shared on this page???
And do I have to change the code first???

@oxesoft
Copy link
Owner

oxesoft commented Nov 5, 2022

I have a broken Roland 61 key keyboard, I want to make it a midi controller, can I use the code shared on this page??? And do I have to change the code first???

The code shared in this page if for making pitch bend and modulation wheel work in the respective repository's code.
Please follow the instructions in https://github.com/oxesoft/keyboardscanner and bring your keyboard back to life.

@seiler-emerson
Copy link

experimente o novo código: https://github.com/andersonbruno02/keyboardscanner o controle muda agora. estou usando o resistor pullup interno do arduino, não preciso adicionar mais resistores. apenas uma conexão com o pino e o aterramento. você também pode tentar mudar a porta para ver se faz diferença.

Anderson, você tem alguma dica para mim adicionar 8 faders e 8 potenciometros e 8 botoes para controlar as layers da daw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants