Thank you "jbellavance" for helping me on this.
Now I have a second problem with this FOR loop! It prevents the following lines from running.
I loaded the code to the Arduino but the next part after the FOR loop which controls 3 switches does not work when the FOR loop is there at the beginning of the void loop ().
Is it possible to do this calculation outside the void loop?
It tried to take it outside but ended up with errors!
Here is my code:
//Roland Jv-1010 Scale Controller.
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();
//Scale ON/OFF Arrays
byte onArray[12] = {0xf0, 0x41, 0x10, 0x6a, 0x12, 0x00, 0x00, 0x00, 0x07, 0x01, 0x78, 0xf7}; // ON array
byte offArray[12] = {0xf0, 0x41, 0x10, 0x6a, 0x12, 0x00, 0x00, 0x00, 0x07, 0x00, 0x79, 0xf7}; // OFF array
// Analog pin A0-ON
int switchPinON = 14;
// Analog pin A1-OFF
int switchPinOFF = 15;
// Analog pin A2-SEND
int scaleSend = 16;
int Do = 2;
int Dos = 3;
int Re = 4;
int Res = 5;
int Mi = 6;
int Fa = 7;
int Fas = 8;
int Sol = 9;
int Sols = 10;
int La = 11;
int Las = 12;
int Si = 13;
void setup() {
MIDI.begin(); //Midi channel = 1 , Baud = 31250
pinMode (switchPinON, INPUT); //Scale ON
pinMode (switchPinOFF, INPUT); //Sclae OFF
pinMode (scaleSend, INPUT); //Scale SEND
pinMode (Do, INPUT);
pinMode (Dos, INPUT);
pinMode (Re, INPUT);
pinMode (Res, INPUT);
pinMode (Mi, INPUT);
pinMode (Fa, INPUT);
pinMode (Fas, INPUT);
pinMode (Sol, INPUT);
pinMode (Sols, INPUT);
pinMode (La, INPUT);
pinMode (Las, INPUT);
pinMode (Si, INPUT);
}
void loop() {
// Roland Checksum calculation
byte checksum();
byte partialSum = 0;
byte SA[22] = {0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x11, 0x40, 0x3a, 0x6d, 0x3e, 0x34, 0x0d, 0x38, 0x6b, 0x3c, 0x6f, 0x40, 0x36, 0x0f, checksum, 0xf7};
for (byte i = 8 ; i <= 19 ; i++)
{
partialSum += SA[i];
}
return 0x80 - (partialSum & 0x7F);
// This part doesn't run when follows the checksum calculation!!!!
// ON - OFF - SEND switches
if (digitalRead(scaleSend) == HIGH)
{
MIDI.sendSysEx(22, SA, true);
delay(1000);
}
if (digitalRead(switchPinON) == HIGH)
{
MIDI.sendSysEx(12, onArray, true);
delay(1000);
}
if (digitalRead(switchPinOFF) == HIGH)
{
MIDI.sendSysEx(12 , offArray, true);
delay(1000);
}
// 12 ON/OFF Switches.
// *************************************** DO
if (digitalRead(Do) == HIGH)
{
SA[8] = 0x0e;
}
else
{
SA[8] = 0x40;
}
// *************************************** DO#
if (digitalRead(Dos) == HIGH)
{
SA[9] = 0x0e;
}
else
{
SA[9] = 0x40;
}
// *************************************** RE
if (digitalRead(Re) == HIGH)
{
SA[10] = 0x0e;
}
else
{
SA[10] = 0x40;
}
// *************************************** RE#
if (digitalRead(Res) == HIGH)
{
SA[11] = 0x0e;
}
else
{
SA[11] = 0x40;
}
// *************************************** MI
if (digitalRead(Mi) == HIGH)
{
SA[12] = 0x0e;
}
else
{
SA[12] = 0x40;
}
// *************************************** FA
if (digitalRead(Fa) == HIGH)
{
SA[13] = 0x0e;
}
else
{
SA[13] = 0x40;
}
// *************************************** FA#
if (digitalRead(Fas) == HIGH)
{
SA[14] = 0x0e;
}
else
{
SA[14] = 0x40;
}
// *************************************** SOL
if (digitalRead(Sol) == HIGH)
{
SA[15] = 0x0e;
}
else
{
SA[15] = 0x40;
}
// *************************************** SOL#
if (digitalRead(Sols) == HIGH)
{
SA[16] = 0x0e;
}
else
{
SA[16] = 0x40;
}
// *************************************** LA
if (digitalRead(La) == HIGH)
{
SA[17] = 0x0e;
}
else
{
SA[17] = 0x40;
}
// *************************************** LA#
if (digitalRead(Las) == HIGH)
{
SA[18] = 0x0e;
}
else
{
SA[18] = 0x40;
}
// *************************************** SI
if (digitalRead(Si) == HIGH)
{
SA[19] = 0x0e;
}
else
{
SA[19] = 0x40;
}
}