Power-up Passcode to Access Void Loop

Hi,
I'm trying to build a MIDI controller, that on start-up requires to input a simple password (4 buttons) to THEN use the controller normally. I got both code working as normal void loop but I can't figure out how I can link them. I think actually that the "Passcode" code cannot be a Void Loop, since once the right password is insert it won't come back again until the arduino is powered. I don't know all the coding function so probably I'm missing the right tool.
Any suggestion on that?

Thanks in advance

Please show the both codes

put the passcode code in setup() to be ran one time at start up.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Please post a schematic.
Please post an image of your project.

Thank you for your answer. I'm sorry I didn't post the codes but i did it on purpose, since it wasn't the direct question (the two codes works indipendently without any problem). My bad, I didn't realize that someone could post the code with already the solution working. Later I will post the codes, thanks!

Here I am, I'm posting the two codes, they work on their own in the same schematic on an Arduino Pro Micro (two buttons wired on A0 and A1 and two leds wired to pin 4 and 6, thats all). They are simplified version I wrote modding two existing codes to test if everything was working, The project will be more complex (I succesfully built a rotary encoder controller in the past, I wanted to implement it).

Passcode code


const int button1 = A0; //first button is on pin 8
const int button2 = A1; //second is on pin 9


const int Red = 4; //red LED is on pin 4
const int greenLed = 6; //green LED is pin 12
void checkEntered1(int button);


int code[] = {1, 1, 2, 1, 1}; //the desired code is entered in this array,
//separated by commas

int entered[7]; //create a new empty array for the code entered by
//the user (has 4 elements)








void setup() { //run once at sketch startup
  Serial.begin(9600); //begin Serial

  pinMode(button1, INPUT_PULLUP); //button 1 is an input
  pinMode(button2, INPUT_PULLUP); //button 2 is an input


  pinMode(greenLed, OUTPUT); // the green LED is an output
  pinMode(Red, OUTPUT);

  digitalWrite(Red, LOW); //turn the red LED on
  for (int i = 0; i < 5; i++) { //work through numbers 0-3
    Serial.println(code[i]); //print each digit of the code
    Serial.println(entered[i]); //print each element of the entered[]array (this was for me to check that it started at 0
  }
}

void loop() { //run repeatedly


  if (digitalRead(button1) == LOW) { //if button1 is pressed
    checkEntered1(1); //call checkEntered and pass it a 1
    delay(250);//wait, needed for correct functioning, otherwise buttons are deemed to be pressed more than once
  }
  else if (digitalRead(button2) == LOW) { //if button2 is pressed   (copio questo se voglio aggiungere bottoni)
    checkEntered1(2); //call checkEntered1 and pass it a 2
    delay(250); //wait
  }
}

void checkEntered1(int button) { //check the first element of the entered[] array

  if (entered[0] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered2(button); //move on to checkEntered2, passing it "button"
  }


  else if (entered[0] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[0] = button; //set the first element as the button that has been pressed
    Serial.print("1: "); Serial.println(entered[0]); //for debugging
  }

}

void checkEntered2(int button) { //check the second element of the entered[] array

  if (entered[1] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered3(button); //move on to checkEntered3, passing it "button"
  }

  else if (entered[1] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[1] = button; //set the second element as the button that has been pressed
    Serial.print("2: "); Serial.println(entered[1]); //for debugging
  }

}

void checkEntered3(int button) { //check the third element of the entered[] array

  if (entered[2] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered4(button); //move on to checkEntered4, passing it "button"
  }

  else if (entered[2] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[2] = button; //set the third element as the button that has been pressed
    Serial.print("3: "); Serial.println(entered[2]); //for debugging
  }

}

void checkEntered4(int button) { //check the third element of the entered[] array

  if (entered[3] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered5(button); //move on to checkEntered4, passing it "button"
  }

  else if (entered[3] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[3] = button; //set the third element as the button that has been pressed
    Serial.print("4: "); Serial.println(entered[3]); //for debugging
  }

}


void checkEntered5(int button) { //check the fourth element of the entered[] array

  if (entered[4] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[4] = button; //set the final element as the button that has been pressed
    Serial.print("5: "); Serial.println(entered[4]); //for debugging
    delay(100); //allow time for processing
    compareCode(); //call the compareCode function
  }
}


void compareCode() { //checks if the code entered is correct by comparing the code[] array with the entered[] array
  for (int i = 0; i < 5; i++) { //these three lines are for debugging
    Serial.println(entered[i]);
  }

  if ((entered[0] == code[0]) && (entered[1] == code[1]) && (entered[2] == code[2]) && (entered[3] == code[3]) && (entered[4] == code[4]) && (entered[5] == code[5])) { //if all the elements of each array are equal
    digitalWrite(Red, LOW); // turn the red LED off
    digitalWrite(greenLed, HIGH); //turn the green LED on
    delay(1000); //wait for a bit
    digitalWrite(greenLed, LOW); //turn the green LED off
    Serial.println("Green");

    for (int i = 0; i < 6; i++) { //this next loop is for debugging
      entered[i] = 0;
    }
  }



  else { //if you (or the intruder) get the code wrong

    digitalWrite(Red, HIGH);
    delay(1000);
    digitalWrite(Red, LOW);
    Serial.println("Red OFF");
    for (int i = 0; i < 7; i++) { //this next loop is for debugging
      entered[i] = 0;
    }

  }
}

Midi Buttons Code

#include "MIDIUSB.h"
#include "Arduino.h"
#include "avdweb_Switch.h"


Switch buttonGND1 = Switch(A0);
Switch buttonGND2 = Switch(A1);

int LED1 = 6;
int LED2 = 4;
int stateLED1 = 0;
int stateLED2 = 0;




void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  Serial.begin (9600);
  //Serial.begin (31250);
  //Serial.begin(115200);

}

void loop()
{

  buttonGND1.poll();
  if (buttonGND1.pushed()) {
    if (stateLED1 == 255) {
      stateLED1 = 0;
      controlChange(15, 106, 0); // channel, control, value
      MidiUSB.flush();
    }
    else {
      stateLED1 = 255;
      controlChange(15, 106, 127); // channel, control, value
      MidiUSB.flush();
    }
    digitalWrite(LED1, stateLED1);
  }

  buttonGND2.poll();  //103
  if (buttonGND2.pushed()) {
    if (stateLED2 == 255) {
      stateLED2 = 0;
      controlChange(15, 105, 0); // channel, control, value
      MidiUSB.flush();
    }
    else {
      stateLED2 = 255;
      controlChange(15, 105, 127); // channel, control, value
      MidiUSB.flush();
    }
    digitalWrite(LED2, stateLED2);
  }
}

Please be forgiving, I know they are poorly written and they use different style of coding, I'm not that expert yet
If you got any suggestion on how to simplify the Passcode code it would be very welcome
Thanks

Is the passcode supposed to stop loop() from running till the passcode is entered?

As soon as setup() exits, loop() starts to run.

So, if you do not want loop() to run until a valid passcode is entered, the passcode has to be checked in setup(). Do not exit setup() until a valid password has been entered.

Yes, exactly. The loop() "Midi Controller" has to start only after the right passcode is entered

It seems the best way to proceed. The problem is I'm not sure I know how to do it... Is there a way to tell the setup to loop until the right passcode is entered?
Thanks

Put the pass code code in setup() at the end of setup() stopping the code from executing further till the thing be done right. Several different kinds of loops for you to get in trouble with,

and you might want to know about this,

In outline:

void setup() {
// setup code below
...
get_passcode();
while (check_passcode() == false) get_passcode();
}

Hi everyone!

After a few days I managed to compile the full code for my project... Everything in functioning correcly and I learnd a few new things that will be super useful for next projects!

If anyone is curious here's the code (5 buttons, one rotary switch, 5 pots and one rotary encoder to send midi messages to my audio interface, not every midi message is mapped, I will tweak the code when needed)

Thanks

#include "MIDI.h"
#include "Arduino.h"
#include "avdweb_Switch.h"
#include <Encoder.h>


//Rotary Encoder
Encoder knob1(A1, A0);
long position1  = -999;
int encodervalue = 0;
//int premutevalue = 0;

//Pot
int analogpot1 = A7;
int analogpot2 = A6;
int analogpot3 = A5;
int analogpot4 = A4;
int analogpot5 = A3;

//Switches
Switch buttonGND1 = Switch(4);
Switch buttonGND2 = Switch(6);
Switch buttonGND3 = Switch(8);
Switch buttonGND4 = Switch(10);
Switch buttonGNDK = Switch(A2);
Switch buttonGNDRotary1 = Switch(3);
Switch buttonGNDRotary3 = Switch(2);




int analogpot1val = 0;
int analogpot1lastval = 0;
int analogpot2val = 0;
int analogpot2lastval = 0;
int analogpot3val = 0;
int analogpot3lastval = 0;
int analogpot4val = 0;
int analogpot4lastval = 0;
int analogpot5val = 0;
int analogpot5lastval = 0;



int stateLED1 = 0;
int stateLED2 = 0;
int stateLED3 = 0;
int stateLED4 = 0;
int stateRed = 0;


const int Red = 13; //red LED is on pin 4
const int LED1 = 5;
const int LED2 = 7;
const int LED3 = 9;
const int LED4 = 11;

MIDI_CREATE_DEFAULT_INSTANCE();

void checkEntered1(int button);

//void noteOn(byte channel, byte pitch, byte velocity) {
//  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
//  MidiUSB.sendMIDI(noteOn);
//}

//void noteOff(byte channel, byte pitch, byte velocity) {
//  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
//  MidiUSB.sendMIDI(noteOff);
//}
//void controlChange(byte channel, byte control, byte value) {
//  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
//  MidiUSB.sendMIDI(event);
//}


int code[] = {1, 1, 3, 2, 4}; //the desired code is entered in this array,
//separated by commas

int entered[7]; //create a new empty array for the code entered by
//the user (has 4 elements)

int check_passcode = false;

void mute() {
  MIDI.sendControlChange(7, encodervalue, 1);
  delay(1);
  MIDI.sendControlChange(7, encodervalue, 1);
  delay(1);
}

void passcode() {
  digitalWrite(Red, HIGH);
  buttonGND1.poll();
  buttonGND2.poll();
  buttonGND3.poll();
  buttonGND4.poll();

  if (buttonGND1.pushed()) { //if button1 is pressed
    checkEntered1(1); //call checkEntered and pass it a 1
    //delay(250);//wait, needed for correct functioning, otherwise buttons are deemed to be pressed more than once
  }
  else if (buttonGND2.pushed()) { //if button2 is pressed
    checkEntered1(2); //call checkEntered1 and pass it a 2
  }
  else if (buttonGND3.pushed()) { //if button3 is pressed
    checkEntered1(3); //call checkEntered1 and pass it a 3
  }
  else if (buttonGND4.pushed()) { //if button2 is pressed   (copio questo se voglio aggiungere bottoni)
    checkEntered1(4); //call checkEntered1 and pass it a 4
  }
}

void checkEntered1(int button) { //check the first element of the entered[] array

  if (entered[0] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered2(button); //move on to checkEntered2, passing it "button"
  }
  else if (entered[0] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[0] = button; //set the first element as the button that has been pressed
    //Serial.print("1: "); Serial.println(entered[0]); //for debugging
  }
}

void checkEntered2(int button) { //check the second element of the entered[] array

  if (entered[1] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered3(button); //move on to checkEntered3, passing it "button"
  }
  else if (entered[1] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[1] = button; //set the second element as the button that has been pressed
    //Serial.print("2: "); Serial.println(entered[1]); //for debugging
  }
}

void checkEntered3(int button) { //check the third element of the entered[] array

  if (entered[2] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered4(button); //move on to checkEntered4, passing it "button"
  }
  else if (entered[2] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[2] = button; //set the third element as the button that has been pressed
    //Serial.print("3: "); Serial.println(entered[2]); //for debugging
  }
}

void checkEntered4(int button) { //check the third element of the entered[] array

  if (entered[3] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered5(button); //move on to checkEntered4, passing it "button"
  }
  else if (entered[3] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[3] = button; //set the third element as the button that has been pressed
    //Serial.print("4: "); Serial.println(entered[3]); //for debugging
  }
}

void checkEntered5(int button) { //check the fourth element of the entered[] array

  if (entered[4] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[4] = button; //set the final element as the button that has been pressed
    //Serial.print("5: "); Serial.println(entered[4]); //for debugging
    delay(100); //allow time for processing
    compareCode(); //call the compareCode function
  }
}


void compareCode() { //checks if the code entered is correct by comparing the code[] array with the entered[] array
  for (int i = 0; i < 5; i++) { //these three lines are for debugging
    //Serial.println(entered[i]);
  }

  if ((entered[0] == code[0]) && (entered[1] == code[1]) && (entered[2] == code[2]) && (entered[3] == code[3]) && (entered[4] == code[4]) && (entered[5] == code[5])) { //if all the elements of each array are equal
    digitalWrite(Red, LOW); // turn the red LED off
    //digitalWrite(Green, HIGH); //turn the green LED on
    //delay(1000); //wait for a bit
    //digitalWrite(Green, LOW); //turn the green LED off
    //Serial.println("Green");
    check_passcode = true;
    for (int i = 0; i < 6; i++) { //this next loop is for debugging
      entered[i] = 0;
    }
  }

  else { //if you (or the intruder) get the code wrong
    digitalWrite(Red, LOW);
    delay(100);
    digitalWrite(Red, HIGH);
    delay(100);
    digitalWrite(Red, LOW);
    delay(100);
    digitalWrite(Red, HIGH);
    delay(100);
    digitalWrite(Red, LOW);
    delay(100);
    digitalWrite(Red, HIGH);
    delay(100);
    digitalWrite(Red, LOW);
    delay(100);
    digitalWrite(Red, HIGH);
    delay(100);
    digitalWrite(Red, LOW);
    //Serial.println("Red OFF");
    for (int i = 0; i < 7; i++) { //this next loop is for debugging
      entered[i] = 0;
    }

  }
}




void setup() { //run once at sketch startup
  //Serial.begin(9600); //begin Serial
  Serial.begin(31250);


  //  pinMode(button1, INPUT_PULLUP); //button 1 is an input
  //  pinMode(button2, INPUT_PULLUP); //button 2 is an input


  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(Red, OUTPUT);


  pinMode (analogpot1, INPUT);
  pinMode (analogpot2, INPUT);
  pinMode (analogpot3, INPUT);
  pinMode (analogpot4, INPUT);
  pinMode (analogpot5, INPUT);


  for (int i = 0; i < 5; i++) { //work through numbers 0-3
    Serial.println(code[i]); //print each digit of the code
    Serial.println(entered[i]); //print each element of the entered[]array (this was for me to check that it started at 0
  }

  while (check_passcode == false) passcode(), mute();

  //MIDI.sendControlChange(7, 0, 1);
}



void loop() {

  //Pots                                                                                                                 //Pots
  analogpot1val = analogRead(analogpot1);
  if (abs(analogpot1val - analogpot1lastval) > 6) // questo è il valore soglia, bisogna sperimentare
  {
    MIDI.sendControlChange(1, analogpot1val / 8, 16); //Midi via 5din
    //      controlChange(9,102,analogpot1val/8);    //Midi via USB
    //      MidiUSB.flush();                         //Midi via USB
    //Serial.println("Pot1"), Serial.println(analogpot1val / 8);
    analogpot1lastval = analogpot1val;
  }

  analogpot2val = analogRead(analogpot2);
  if (abs(analogpot2val - analogpot2lastval) > 6) // questo è il valore soglia, bisogna sperimentare
  {
    MIDI.sendControlChange(2, analogpot2val / 8, 16); //Midi via 5din
    //      controlChange(9,102,analogpot1val/8);    //Midi via USB
    //      MidiUSB.flush();                         //Midi via USB
    //Serial.println("Pot2"), Serial.println(analogpot2val / 8);
    analogpot2lastval = analogpot2val;
  }

  analogpot3val = analogRead(analogpot3);
  if (abs(analogpot3val - analogpot3lastval) > 6) // questo è il valore soglia, bisogna sperimentare
  {
    MIDI.sendControlChange(3, analogpot3val / 8, 16); //Midi via 5din
    //      controlChange(9,102,analogpot1val/8);    //Midi via USB
    //      MidiUSB.flush();                         //Midi via USB
    //Serial.println("Pot3"), Serial.println(analogpot3val / 8);
    analogpot3lastval = analogpot3val;
  }

  analogpot4val = analogRead(analogpot4);
  if (abs(analogpot4val - analogpot4lastval) > 6) // questo è il valore soglia, bisogna sperimentare
  {
    MIDI.sendControlChange(4, analogpot4val / 8, 16); //Midi via 5din
    //      controlChange(9,102,analogpot1val/8);    //Midi via USB
    //      MidiUSB.flush();                         //Midi via USB
    //Serial.println("Pot4"), Serial.println(analogpot4val / 8);
    analogpot4lastval = analogpot4val;
  }

  analogpot5val = analogRead(analogpot5);
  if (abs(analogpot5val - analogpot5lastval) > 6) // questo è il valore soglia, bisogna sperimentare
  {
    //MIDI.sendControlChange(7, analogpot5val / 8, 1); //Midi via 5din
    //      controlChange(9,102,analogpot1val/8);    //Midi via USB
    //      MidiUSB.flush();                         //Midi via USB
    //Serial.println("Pot5"), Serial.println(analogpot5val / 8);
    analogpot5lastval = analogpot5val;
  }



  // Rotary Encoder                                                                                                     //Rotary Encoder

  long new1;
  new1 = knob1.read();

  if (new1 != position1) {
    if (new1 > position1) {
      //Serial.print("Knob1 = UP");

      //      if (buttonGNDMID.on()) {
      //        MIDI.sendControlChange(1, 3, 2);
      //      }
      //      else                  {
      //        MIDI.sendControlChange(21, 3, 2);
      //      }
      //Serial.println("Knob"), Serial.println(encodervalue + 1);
    { if (encodervalue + 1 < 126)  {
          encodervalue = encodervalue + 1;
          MIDI.sendControlChange(7, encodervalue + 1, 1);
        }
        else  encodervalue = 127;
        MIDI.sendControlChange(7, encodervalue, 1);
      }
    }
    else                  {
      //Serial.print("Knob1 = DW");

      //      if (buttonGNDMID.on()) {
      //        MIDI.sendControlChange(1, 125, 2);
      //      }
      //      else                  {
      //        MIDI.sendControlChange(21, 125, 2);
      //Serial.println("Knob"), Serial.println(encodervalue - 1);
      //encodervalue = encodervalue - 1;
    { if (encodervalue - 1 > 1) {
          encodervalue = encodervalue - 1;
          MIDI.sendControlChange(7, encodervalue - 1, 1);
        }
        else  encodervalue = 0;
        MIDI.sendControlChange(7, encodervalue, 1);
      }
    }

  }
  position1 = new1;
  //}

  //buttons                                                                                                     //Buttons

  buttonGND1.poll();                    //Reference 1
  if (buttonGND1.pushed()) {
    if (stateLED1 == 255) {
      stateLED1 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    else {
      stateLED1 = 255;
      stateLED2 = 0;
      stateLED3 = 0;
      stateLED4 = 0;
      MIDI.sendControlChange(109, 127, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    digitalWrite(LED1, stateLED1);
    digitalWrite(LED2, stateLED2);
    digitalWrite(LED3, stateLED3);
    digitalWrite(LED4, stateLED4);
  }


  buttonGND2.poll();                    //Reference 2
  if (buttonGND2.pushed()) {
    if (stateLED2 == 255) {
      stateLED2 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    else {
      stateLED1 = 0;
      stateLED2 = 255;
      stateLED3 = 0;
      stateLED4 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 127, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    digitalWrite(LED1, stateLED1);
    digitalWrite(LED2, stateLED2);
    digitalWrite(LED3, stateLED3);
    digitalWrite(LED4, stateLED4);
  }

  buttonGND3.poll();                     //Reference 3
  if (buttonGND3.pushed()) {
    if (stateLED3 == 255) {
      stateLED3 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    else {
      stateLED1 = 0;
      stateLED2 = 0;
      stateLED3 = 255;
      stateLED4 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 127, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    digitalWrite(LED1, stateLED1);
    digitalWrite(LED2, stateLED2);
    digitalWrite(LED3, stateLED3);
    digitalWrite(LED4, stateLED4);
  }


  buttonGND4.poll();                     //Reference 3
  if (buttonGND4.pushed()) {
    if (stateLED4 == 255) {
      stateLED4 = 0;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 0, 16);
    }
    else {
      stateLED1 = 0;
      stateLED2 = 0;
      stateLED3 = 0;
      stateLED4 = 255;
      MIDI.sendControlChange(109, 0, 16);
      MIDI.sendControlChange(108, 0, 16);
      MIDI.sendControlChange(107, 0, 16);
      MIDI.sendControlChange(106, 127, 16);
    }
    digitalWrite(LED1, stateLED1);
    digitalWrite(LED2, stateLED2);
    digitalWrite(LED3, stateLED3);
    digitalWrite(LED4, stateLED4);
  }

  buttonGNDK.poll();  //103
  if (buttonGNDK.pushed()) {
    if (stateRed == 255) {
      stateRed = 0;
      //      controlChange(15, 105, 0); // channel, control, value
      //     MidiUSB.flush();
      MIDI.sendNoteOff(44, 0, 1); //cc, value, channel
    }
    else {
      stateRed = 255;
      //      controlChange(15, 105, 127); // channel, control, value
      //      MidiUSB.flush();
      MIDI.sendNoteOff(44, 127, 1); //cc, value, channel
    }
    digitalWrite(Red, stateRed);
  }


  buttonGNDRotary1.poll();
  if (buttonGNDRotary1.pushed()) {
    //Serial.println ("Pos1");
    MIDI.sendControlChange(51, 127, 3);
  }
  if (buttonGNDRotary1.released()) {
    //Serial.println ("Not Pos1");
    MIDI.sendControlChange(51, 0, 3);
  }

  buttonGNDRotary3.poll();
  if (buttonGNDRotary3.pushed()) {
    //Serial.println ("Pos3");
    MIDI.sendControlChange(52, 127, 3);
  }
  if (buttonGNDRotary3.released()) {
    //Serial.println ("Not Pos3");
    MIDI.sendControlChange(52, 0, 3);
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.