Hello everyone, this is my first post so I'm gonna introduce me
I'm Karím. I'm 14 yrs old and I'm from Argentina.
Some weeks ago, I started my first Arduino project: A MIDI Controller for DAWs and DJs software.
I've almost finished the code for buttons, encoders and potentiometers out. Now I'm in the 'MIDI LED feedback' part.
I want to get LED on when the button is pressed with a code like this:
#define boton1 51
#define boton1led 50
int keyispressed1 = 0;
int noteisplaying1 = 0;
void setup() {
Serial.begin (115200);
pinMode(boton1, INPUT);
pinMode(boton1led, OUTPUT);
digitalWrite(boton1, HIGH);
}
void loop() {
keyispressed1 = digitalRead(boton1);
if (keyispressed1 == LOW){ //BOTON 1
if(!noteisplaying1){
digitalWrite(boton1led, HIGH);
noteisplaying1 = 1;
}
}
else{
if(noteisplaying1){
digitalWrite(boton1led, LOW);
noteisplaying1 = 0;
}
}
}
( I took off the MIDI out part for give you a shorter code )
But also, if the button I pressed has a toggle function in the software (like "Play", something that still activated after "un-press"), I want to send a message from the software (I tried and it's possible) and somehow get the LED still on. (Sorry for my bad english, this is very hard to explain hahaha).
The software can send:
A "note on" with velocity "127" when the function is activated, and velocity "0" when is desactivated.
Also, it can send a "Control Change" with same configuration of velocity.
I tried with reading "raw" serial and with the MIDI Library too, but I don't get it working...
byte message;
byte note;
byte velocity;
int led = 13;
void setup() {
pinMode(led,OUTPUT);
Serial.begin(115200);
digitalWrite(led,LOW);
}
void loop () {
if (Serial.available() > 0) {
message = Serial.read();
note = Serial.read();
velocity = Serial.read();
if (message == 144){
if(note == 72) {
if(velocity == 127) {
digitalWrite(led, HIGH);
} else {
if(velocity == 0) {
digitalWrite(led, LOW);
}
}
}
}
}
}
#include <MIDI.h>
byte led = 13;
byte channel = 1;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(115200);
}
void loop() {
if (MIDI.read(channel)) {
if (MIDI.getType() == ControlChange) {
if (MIDI.getData1() == 1 ) {
if (MIDI.getData2() == 127 ) {
digitalWrite(led, HIGH);
} else {
if (MIDI.getData2() == 0 ) {
digitalWrite(led, HIGH);
}
}
}
}
}
}
PLEASE HELP ME, I can't figure how get it working!
Thank you!