how can i use the midi signals.
i get how to use the "wire" library and the "midi" library seperatly, but when i try to combine the 2 im having issues. please help!
how can i use the midi signals.
i get how to use the "wire" library and the "midi" library seperatly, but when i try to combine the 2 im having issues. please help!
Attach wiring diagram and code.
this is the wiring diagram i have.
i have no idea what im doing lol
please help. HAALLP
#include <Wire.h>
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int x ;
void setup() {
Wire.begin();
MIDI.begin();
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
MIDI.read();
Wire.beginTransmission(8); // transmit to device #9
Wire.write(x); // sends x
Wire.endTransmission();
}
void handleNoteOn(byte channel, byte note, byte velocity){
// Check if note is in range
if(note == 48){
Wire.write(48);
}
}
void handleNoteOff(byte channel, byte note, byte velocity){
// Check if note is in range
if(note == 48){
x = 12;
}
}
For the moment the. JPG file does not open.
What is the purpose of the project? How is it intended to work? What does actualy happend?
Just asking for help does not tell what the issue us.
beensolo:
i get how to use the "wire" library and the "midi" library seperatly, but when i try to combine the 2 im having issues. please help!
Does "I get how to..." mean that you have separate programs one of which successfully gets MIDI input and the other communicates something via Wire? If so then please post them.
And please give more details of what problems your current program has. Just saying you are "having issues" isn't very useful.
Steve
If I remember how that MIDI library works, the note handler function is an interrupt handler.
Try moving the wire.write() calls outside it. Set a flag instead and do the wire.write() in loop()
so i am using midi signal as input from hairless from computer. i posted this on a seperate post but people were saying to use spi and i2c or shift registers. im just totally new at this. i want to be able to control multiple relays and addressable leds with a midi signal either from a midi player or a music program like live or pro tools.
//slave code
int digitalPinin = 10;
int in1 = 2;
float pulseWidth = 0;
void setup() {
Serial.begin(9600);
pinMode(in1, OUTPUT);
digitalWrite(in1, HIGH);
}
void loop() {
pulseWidth = pulseIn (digitalPinin,HIGH) / 100;
Serial.println(pulseWidth);
if(pulseWidth == 10)digitalWrite(in1, LOW);
}
//master code
#include <MIDI.h>
#define NOTESTART 40
static const uint8_t
minNote = NOTESTART,
struct CustomBaud : public midi::DefaultSettings{
static const long BaudRate = 115200;
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaud);
int slaveD = 11;
void setup() {
pinMode(slaveD, OUTPUT);
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
MIDI.read();
}
void handleNoteOn(byte channel, byte note, byte velocity){
if(note < minNote ){
analogWrite(slaveD, 127);
}
}
void handleNoteOff(byte channel, byte note, byte velocity){
// Check if note is in range
analogWrite(slaveD, 0);
}
//i2c slave
#include <Wire.h>
int x = 0;
int ie1 = 2;
int ie2 = 3;
void setup() {
Serial.begin(9600);
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(requestEvent); // register event
pinMode(ie1, OUTPUT);
digitalWrite(ie1, HIGH);
pinMode(ie2, OUTPUT);
digitalWrite(ie2, HIGH);
}
void requestEvent(int bytes) {
x = Wire.read();
}
void loop() {
Serial.println(x);
}
//master
#include <MIDI.h>
#define NOTESTART 40
static const uint8_t
minNote = NOTESTART,
struct CustomBaud : public midi::DefaultSettings{
static const long BaudRate = 115200;
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaud);
int slaveD = 11;
void setup() {
pinMode(slaveD, OUTPUT);
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
MIDI.read();
}
void handleNoteOn(byte channel, byte note, byte velocity){
if(note < minNote ){
analogWrite(slaveD, 127);
}
}
void handleNoteOff(byte channel, byte note, byte velocity){
// Check if note is in range
analogWrite(slaveD, 127)
}
GypsumFantastic:
If I remember how that MIDI library works, the note handler function is an interrupt handler.Try moving the wire.write() calls outside it. Set a flag instead and do the wire.write() in loop()
can you go in to more detail? explain like im a 5 year old