Ok, ho risolto.
Avevo dei problemi con le periferiche esterne e con una resistenza sul midi out.
Allego gli schemi funzionanti per chi ci legge così da marcare come testati i circuiti.
Adesso però mi ritrovo con un piccolo problemino lato codice.
Questo pedale ha queste funzioni:
-
Riceve messaggi midi (con circuito midi in) di tipo Control Change (CC) ed aziona in base al messaggio dei pin digitali su HIGH o LOW (serve per azionare dei footswitch di un Laney IRT30)
-
Trasforma il segnale di 5 pulsanti (footswitch momentary) e di un potenziometro in segnale midi (tramite un midi out)
Vorrei aggiungere un led che di base ha un effetto pulse (solo per controllare che al pedale arrivi corrente e sia acceso). Il problema è che se inserisco la funzione del led nel loop() mi sballa tutta la catena midi, alterando tutte le funzionalità (manda dei messaggi errati ed i pulsanti e il potenziometro non funziona). Ho provato a creare una funzione e farla girare nel setup() ma il risultato è il led acceso.. stop. Non pulsa.
Sapreste aiutarmi a capire il perchè? Riporto il codice.
Intanto grazie ancora per gli aiuti.
P.s: LED1 è il led che dovrebbe pulsare, LEDCONTROLLO è il 13 su Arduino e l'ho usato per il debugging
P.s.: Controller.h è una libreria reperibile in questo tutorial
P.p.p.s.: mi piacerebbe implementare al posto del led pulse (che attualmente è un led blu) un led RGB che pulsa di blu di base e che, al ricevere di segnali midi lampeggia di rosso, all'emettere di segnali midi lampeggia di arancio. Su questo vedremo se riusciamo in un secondo momento.
#include <MIDI.h>
#include "Controller.h"
// Define labels for the AMP's pins
#define RELAY1 4 // LEAD
#define RELAY2 5 // CLEAN
#define RELAY3 6 // REVERB
#define RELAY4 7 // BOOST
//Define LED's pin
const int LED1 = 3;
const int LEDCONTROLLO = 13;
//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();
// Define labels for the POT & FOOTSWITCHES's pin
byte NUMBER_BUTTONS = 1;
byte NUMBER_POTS = 1;
//Pot (Pin Number, Command, CC Control, Channel Number)
Pot PO1(A0, 0, 24, 13);
Pot *POTS[] {&PO1};
//***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
//Button (Pin Number, Command, Note Number, Channel, Debounce Time)
//** Command parameter 0=NOTE 1=CC 2=Toggle CC **
Button BU1(8, 2, 25, 13, 5 );
Button BU2(9, 2, 26, 13, 5 );
Button BU3(10, 2, 27, 13, 5 );
Button BU4(11, 2, 28, 13, 5 );
Button BU5(12, 2, 29, 13, 5 );
Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5};
void setup() {
pinMode(RELAY1, OUTPUT); //PIN in uscita LEAD
pinMode(RELAY2, OUTPUT); //PIN in uscita CLEAN
pinMode(RELAY3, OUTPUT); //PIN in uscita REVERB
pinMode(RELAY4, OUTPUT); //PIN in uscita BOOST
pinMode (LED1, OUTPUT); //PIN in uscita LED
pinMode (LEDCONTROLLO, OUTPUT); //PIN in uscita LED CONTROLLO
MIDI.begin(13);
//MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleControlChange(MyCCFunction); // This command tells the MIDI Library
// the function you want to call when a Continuous Controller command
// is received. In this case it's "MyCCFunction".
//Richiamo il lampeggio del led
LampeggioLed();
}
void loop() { // Main loop
if (NUMBER_BUTTONS != 0) updateButtons();
if (NUMBER_POTS != 0) updatePots();
MIDI.read(); // Continuously check if Midi data has been received.
}
//*****************FUNZIONI******************
//LAMPEGGIO LED
void LampeggioLed() {
float in, out;
for (in = 0; in < 6.283; in = in + 0.001)
{
out = sin(in) * 127.5 + 127.5;
analogWrite(LED1,out);
delay(1);
}
}
// MyCCFunction is the function that will be called by the Midi Library
// when a Continuous Controller message is received.
// It will be passed bytes for Channel, Controller Number, and Value
// It checks if the controller number is within the 22 to 27 range
// If it is, light up the corresponding LED with the PWM brightness equal to the Value byte
void MyCCFunction(byte channel, byte number, byte value) {
switch (number) {
case 20:
if (value > 0)
{
digitalWrite(RELAY1,HIGH);
}
else
{
digitalWrite(RELAY1,LOW);
}
break;
case 21:
if (value > 0)
{
digitalWrite(RELAY2,HIGH);
}
else
{
digitalWrite(RELAY2,LOW);
}
break;
case 22:
if (value > 0)
{
digitalWrite(RELAY3,HIGH);
}
else
{
digitalWrite(RELAY3,LOW);
}
break;
case 23:
if (value > 0)
{
digitalWrite(RELAY4,HIGH);
}
else
{
digitalWrite(RELAY4,LOW);
}
break;
}
}
//**********************BUTTONS*************************
void updateButtons() {
// Cycle through Button array
for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
byte message = BUTTONS[i]->getValue();
// Button is pressed
if (message == 0) {
switch (BUTTONS[i]->Bcommand) {
case 0: //Note
MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
break;
case 1: //CC
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
break;
case 2: //Toggle
if (BUTTONS[i]->Btoggle == 0) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
BUTTONS[i]->Btoggle = 1;
}
else if (BUTTONS[i]->Btoggle == 1) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
BUTTONS[i]->Btoggle = 0;
}
break;
}
}
// Button is not pressed
if (message == 1) {
switch (BUTTONS[i]->Bcommand) {
case 0:
MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
break;
case 1:
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
break;
}
}
}
}
//***********************POTS*****************************
void updatePots() {
for (int i = 0; i < NUMBER_POTS; i = i + 1) {
byte potmessage = POTS[i]->getValue();
if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
}
}

