Bonjour c'est peut être pas exactement le bon forum mais voilà je cherche à transmettre du signal midi entre des arduino en passant par des RF24 , et je patauge..
à tout hazard quelqu’un sait faire ça?
J’ai un clavier midi qui envoie du signal dans un arduino, lequel est branché sur un rf24 « émetteur », de l’autre coté j’ai un rf24 » récepteur » branché sur un arduino qui doit allumer des leds correspondant aux notes du clavier: les leds s’allument bien mais seulement une fraction de seconde…
j’ai essayé le truc des condensateurs sur l'alim 3,3v des rf24 mais ça ne change rien, je pense que le problème est dans le code mais caramba!! je ne sais pas quoi..
c'est pour ce projet:
https://www.youtube.com/watch?v=KDU3pxHR2I4
https://www.youtube.com/watch?v=bVYyJlxziW0
https://www.youtube.com/watch?v=OSud_ftKwJE
jérémie
transmettre du midi avec des radios rf24
Modérateur : Francois
Re: transmettre du midi avec des radios rf24
j'allais oublier le code.. l'émetteur
le récepteur
- #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
int inByte;
const byte rxAddr[6] = "00001";
void setup()
{
radio.begin();
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);
radio.stopListening();
Serial.begin (31250);
}
void loop()
{if (Serial.available())
{
inByte = Serial.read();
Serial.write(inByte);
}
//radio.write(&inByte, sizeof(inByte));
radio.write(&inByte, 1);
}
le récepteur
- #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
byte note; //
byte velocity; //
int action=2; //
void setup()
{
pinMode(3,OUTPUT); //R2
pinMode(4,OUTPUT); //R3
pinMode(5,OUTPUT); //R4
while (!Serial);
Serial.begin(31250);
radio.begin();
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop()
{ byte incomingByte;
if (radio.available())
{
radio.read(&incomingByte, 1);
}
// if (Serial.available() > 0) {
// incomingByte = Serial.read();
// wait for as status-byte, channel 3, note on or off
switch(incomingByte)
{
case 146: // note on message starting
action=1;
break;
case 130: // note off message starting
action=0;
break;
case 208: // aftertouch not implemented yet
break;
case 162: // polypressure not implemented yet
break;
} if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
note=incomingByte;
playNote(note, 0);
note=0;
velocity=0;
action=2;
}else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
note=incomingByte;
}else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
velocity=incomingByte;
playNote(note, velocity);
note=0;
velocity=0;
action=0;
}else{
//nada
}
}
void playNote(byte note, byte velocity){
int value=LOW;
if (velocity >10){
value=HIGH;
}else{
value=LOW;
}
if(note== 60){
digitalWrite(3, value);
}
if(note== 64){
digitalWrite(4, value);
}
if(note== 67){
digitalWrite(5, value);
}
}