Hello guys! Sorry by my bad english! My name is Michael Piders and im brazilian and i need some HELP!

I has two codes, and it works fine alone, but when i try to turn all in one...

I need all codes together to make my generic MCP with Electricals.

The electricals with switches and buttons is working fine. The encoders works too, but no so good. So when i put both codes together nothing more works!

Let me present to you the codes:

The first one... Switches and Buttons. Used on Arduino UNO.


//DECLARANDO SWITCHES
int SW_BATERIA = 2;
int SW_PAINEL = 3;
int SW_AVIONICS = 4;
int SW_BEACON = 5;
int SW_NAVLIGHTS = 6;
int SW_TAXI = 7;
int SW_LANDLIGHTS = 8;
int SW_GERADOR = 9;
int SW_START = 10;
int SW_PARKING = 11;

//DECLARANDO BOTÕES

const int BT_AP = 12;
int buttonStateBT_AP;
int lastButtonStateBT_AP = HIGH;
long lastDebounceTimeBT_AP = 0;
long debounceDelayBT_AP = 50;

const int BT_AP_FD = 13;
int buttonStateBT_AP_FD;
int lastButtonStateBT_AP_FD = HIGH;
long lastDebounceTimeBT_AP_FD = 0;
long debounceDelayBT_AP_FD = 50;

const int BT_AP_HDG = 14;
int buttonStateBT_AP_HDG;
int lastButtonStateBT_AP_HDG = HIGH;
long lastDebounceTimeBT_AP_HDG = 0;
long debounceDelayBT_AP_HDG = 50;

const int BT_AP_ALT = 15;
int buttonStateBT_AP_ALT;
int lastButtonStateBT_AP_ALT = HIGH;
long lastDebounceTimeBT_AP_ALT = 0;
long debounceDelayBT_AP_ALT = 50;

const int BT_AP_NAV = 16;
int buttonStateBT_AP_NAV;
int lastButtonStateBT_AP_NAV = HIGH;
long lastDebounceTimeBT_AP_NAV = 0;
long debounceDelayBT_AP_NAV = 50;

const int BT_AP_APP = 17;
int buttonStateBT_AP_APP;
int lastButtonStateBT_AP_APP = HIGH;
long lastDebounceTimeBT_AP_APP = 0;
long debounceDelayBT_AP_APP = 50;

const int BT_AP_SPD = 18;
int buttonStateBT_AP_SPD;
int lastButtonStateBT_AP_SPD = HIGH;
long lastDebounceTimeBT_AP_SPD = 0;
long debounceDelayBT_AP_SPD = 50;

const int BT_GPS = 19;
int buttonStateGPS;
int lastButtonStateGPS = HIGH;
long lastDebounceTimeGPS = 0;
long debounceDelayGPS = 50;

const int BT_SYNC = 20;
int buttonStateSYNC;
int lastButtonStateSYNC = HIGH;
long lastDebounceTimeSYNC = 0;
long debounceDelaySYNC = 50;

void setup(){

// ATIVANDO PORTA SERIAL
Serial.begin(115200);

// ATIVANDO SWITCHES

pinMode(SW_BATERIA, INPUT_PULLUP);
digitalWrite(SW_BATERIA,HIGH);

pinMode(SW_PAINEL, INPUT_PULLUP);
digitalWrite(SW_PAINEL,HIGH);

pinMode(SW_AVIONICS, INPUT_PULLUP);
digitalWrite(SW_AVIONICS,HIGH);

pinMode(SW_BEACON, INPUT_PULLUP);
digitalWrite(SW_BEACON,HIGH);

pinMode(SW_NAVLIGHTS, INPUT_PULLUP);
digitalWrite(SW_NAVLIGHTS,HIGH);

pinMode(SW_TAXI, INPUT_PULLUP);
digitalWrite(SW_TAXI,HIGH);

pinMode(SW_LANDLIGHTS, INPUT_PULLUP);
digitalWrite(SW_LANDLIGHTS,HIGH);

pinMode(SW_GERADOR, INPUT_PULLUP);
digitalWrite(SW_GERADOR,HIGH);

pinMode(SW_START, INPUT_PULLUP);
digitalWrite(SW_START,HIGH);

pinMode(SW_PARKING, INPUT_PULLUP);
digitalWrite(SW_PARKING,HIGH);

//ATIVANDO BOTOES

pinMode(BT_AP, INPUT);
digitalWrite(BT_AP,HIGH);

pinMode(BT_AP_FD, INPUT);
digitalWrite(BT_AP_FD,HIGH);

pinMode(BT_AP_HDG, INPUT);
digitalWrite(BT_AP_HDG,HIGH);

pinMode(BT_AP_ALT, INPUT);
digitalWrite(BT_AP_ALT,HIGH);

pinMode(BT_AP_NAV, INPUT);
digitalWrite(BT_AP_NAV,HIGH);

pinMode(BT_AP_APP, INPUT);
digitalWrite(BT_AP_APP,HIGH);

pinMode(BT_AP_SPD, INPUT);
digitalWrite(BT_AP_SPD,HIGH);

pinMode(BT_GPS, INPUT);
digitalWrite(BT_GPS,HIGH);

pinMode(BT_SYNC, INPUT);
digitalWrite(BT_SYNC,HIGH);

void loop(){

delay(500);

// Acionamento dos SWITCHES

if(digitalRead(SW_BATERIA)==LOW){
Serial.println("E18");}//SW_ON
else{
Serial.println("E17");}//SW_OFF

if(digitalRead(SW_PAINEL)==LOW){
Serial.println("C461");//SW_ON
Serial.println("C501");}//SW_ON
else{
Serial.println("C460");//SW_OFF
Serial.println("C500");}//SW_OFF

if(digitalRead(SW_AVIONICS)==LOW){
Serial.println("A431");}//SW_ON
else{
Serial.println("A430");}//SW_OFF

if(digitalRead(SW_BEACON)==LOW){
Serial.println("C421");}//SW_ON
else{
Serial.println("C420");}//SW_OFF

if(digitalRead(SW_NAVLIGHTS)==LOW){
Serial.println("C411");//SW_ON
Serial.println("C491");//SW_ON
Serial.println("C451");}//SW_ON
else{
Serial.println("C410");//SW_OFF
Serial.println("C490");//SW_OFF
Serial.println("C450");}//SW_OFF

if(digitalRead(SW_TAXI)==LOW){
Serial.println("C441");}//SW_ON
else{
Serial.println("C440");}//SW_OFF

if(digitalRead(SW_LANDLIGHTS)==LOW){
Serial.println("C431");//SW_ON
Serial.println("C481");//SW_ON
Serial.println("C471");}//SW_ON
else{
Serial.println("C430");//SW_OFF
Serial.println("C480");//SW_OFF
Serial.println("C470");}//SW_OFF

if(digitalRead(SW_GERADOR)==LOW){
Serial.println("E21");//SW_ON
Serial.println("E24");}//SW_ON
else{
Serial.println("E20");//SW_OFF
Serial.println("E23");}//SW_OFF

if(digitalRead(SW_START)==LOW){
Serial.println("E42");//SW_ON
Serial.println("E45");}//SW_ON
else{
Serial.println("E43");//SW_OFF
Serial.println("E46");}//SW_OFF

if(digitalRead(SW_PARKING)==LOW){
Serial.println("C041");}//SW_ON
else{
Serial.println("C040");}//SW_OFF

// Acionamento dos BOTÕES

int readingBT_AP = digitalRead(BT_AP);
if (readingBT_AP != lastButtonStateBT_AP) { // IF1
lastDebounceTimeBT_AP = millis();} // end IF1
if ((millis() - lastDebounceTimeBT_AP) > debounceDelayBT_AP) { // IF2
if (readingBT_AP != buttonStateBT_AP) { //IF3
buttonStateBT_AP = readingBT_AP;
if (buttonStateBT_AP == HIGH) { // IF4
Serial.println("B01");} // end IF4
else{ // ELSE
Serial.println("B17");} // end ELSE
} // end IF3
} // end IF2
lastButtonStateBT_AP = readingBT_AP;

int readingBT_AP_FD = digitalRead(BT_AP_FD);
if (readingBT_AP_FD != lastButtonStateBT_AP_FD) { // IF1
lastDebounceTimeBT_AP_FD = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_FD) > debounceDelayBT_AP_FD) { // IF2
if (readingBT_AP_FD != buttonStateBT_AP_FD) { // IF3
buttonStateBT_AP_FD = readingBT_AP_FD;
if (buttonStateBT_AP_FD == HIGH) { // IF4
Serial.println("B34"); // FIM IF4
Serial.println("B30");}
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_FD = readingBT_AP_FD;

int readingBT_AP_HDG = digitalRead(BT_AP_HDG);
if (readingBT_AP_HDG != lastButtonStateBT_AP_HDG) { // IF1
lastDebounceTimeBT_AP_HDG = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_HDG) > debounceDelayBT_AP_HDG) { // IF2
if (readingBT_AP_HDG != buttonStateBT_AP_HDG) { //IF3
buttonStateBT_AP_HDG = readingBT_AP_HDG;
if (buttonStateBT_AP_HDG == HIGH) { // IF4
Serial.println("B04");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_HDG = readingBT_AP_HDG;

int readingBT_AP_ALT = digitalRead(BT_AP_ALT);
if (readingBT_AP_ALT != lastButtonStateBT_AP_ALT) { // IF1
lastDebounceTimeBT_AP_ALT = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_ALT) > debounceDelayBT_AP_ALT) { // IF2
if (readingBT_AP_ALT != buttonStateBT_AP_ALT) { //IF3
buttonStateBT_AP_ALT = readingBT_AP_ALT;
if (buttonStateBT_AP_ALT == HIGH) { // IF4
Serial.println("B05");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_ALT = readingBT_AP_ALT;

int readingBT_AP_NAV = digitalRead(BT_AP_NAV);
if (readingBT_AP_NAV != lastButtonStateBT_AP_NAV) { // IF1
lastDebounceTimeBT_AP_NAV = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_NAV) > debounceDelayBT_AP_NAV) { // IF2
if (readingBT_AP_NAV != buttonStateBT_AP_NAV) { //IF3
buttonStateBT_AP_NAV = readingBT_AP_NAV;
if (buttonStateBT_AP_NAV == HIGH) { // IF4
Serial.println("B10");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_NAV = readingBT_AP_NAV;

int readingBT_AP_APP = digitalRead(BT_AP_APP);
if (readingBT_AP_APP != lastButtonStateBT_AP_APP) { // IF1
lastDebounceTimeBT_AP_APP = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_APP) > debounceDelayBT_AP_APP) { // IF2
if (readingBT_AP_APP != buttonStateBT_AP_APP) { //IF3
buttonStateBT_AP_APP = readingBT_AP_APP;
if (buttonStateBT_AP_APP == HIGH) { // IF4
Serial.println("B08");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_APP = readingBT_AP_APP;

int readingBT_AP_SPD = digitalRead(BT_AP_SPD);
if (readingBT_AP_SPD != lastButtonStateBT_AP_SPD) { // IF1
lastDebounceTimeBT_AP_SPD = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_SPD) > debounceDelayBT_AP_SPD) { // IF2
if (readingBT_AP_SPD != buttonStateBT_AP_SPD) { //IF3
buttonStateBT_AP_SPD = readingBT_AP_SPD;
if (buttonStateBT_AP_SPD == HIGH) { // IF4
Serial.println("B26");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_SPD = readingBT_AP_SPD;

int readingGPS = digitalRead(BT_GPS);
if (readingGPS != lastButtonStateGPS) { // IF1
lastDebounceTimeGPS = millis();} // FIM IF1
if ((millis() - lastDebounceTimeGPS) > debounceDelayGPS) { // IF2
if (readingGPS != buttonStateGPS) { //IF3
buttonStateGPS = readingGPS;
if (buttonStateGPS == HIGH) { // IF4
Serial.println("A54");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateGPS = readingGPS;

int readingSYNC = digitalRead(BT_SYNC);
if (readingSYNC != lastButtonStateSYNC) { // IF1
lastDebounceTimeSYNC = millis();} // FIM IF1
if ((millis() - lastDebounceTimeSYNC) > debounceDelaySYNC) { // IF2
if (readingSYNC != buttonStateSYNC) { //IF3
buttonStateSYNC = readingSYNC;
if (buttonStateSYNC == HIGH) { // IF4
Serial.println("E33");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateGPS = readingGPS;
}

Now the second code... Encoders. Used on Arduino UNO also.


//DECLARANDO ROTARY ENCODERS

int RTY_AP_VERTSPD_A = 2;
int RTY_AP_VERTSPD_B = 3;
int RTY_AP_VERTSPD_Agora = 0;
int RTY_AP_VERTSPD_Antes = LOW;
int ContRTY_AP_VERTSPD = LOW;

int RTY_AP_ALT_A = 4;
int RTY_AP_ALT_B = 5;
int RTY_AP_ALT_Agora = 0;
int RTY_AP_ALT_Antes = LOW;
int ContRTY_AP_ALT = LOW;

int RTY_AP_HDG_A = 6;
int RTY_AP_HDG_B = 7;
int RTY_AP_HDG_Agora = 0;
int RTY_AP_HDG_Antes = LOW;
int ContRTY_AP_HDG = LOW;

int RTY_AP_IAS_A = 8;
int RTY_AP_IAS_B = 9;
int RTY_AP_IAS_Agora = 0;
int RTY_AP_IAS_Antes = LOW;
int ContRTY_AP_IAS = LOW;

int RTY_AP_COURSE_A = 10;
int RTY_AP_COURSE_B = 11;
int RTY_AP_COURSE_Agora = 0;
int RTY_AP_COURSE_Antes = LOW;
int ContRTY_AP_COURSE = LOW;

void setup(){

// ATIVANDO PORTA SERIAL

Serial.begin(115200);

//ATIVANDO ROTARY ENCODERS

pinMode (RTY_AP_VERTSPD_A,INPUT_PULLUP);
pinMode (RTY_AP_VERTSPD_B,INPUT_PULLUP);

pinMode (RTY_AP_ALT_A,INPUT_PULLUP);
pinMode (RTY_AP_ALT_B,INPUT_PULLUP);

pinMode (RTY_AP_HDG_A,INPUT_PULLUP);
pinMode (RTY_AP_HDG_B,INPUT_PULLUP);

pinMode (RTY_AP_IAS_A,INPUT_PULLUP);
pinMode (RTY_AP_IAS_B,INPUT_PULLUP);

pinMode (RTY_AP_COURSE_A,INPUT_PULLUP);
pinMode (RTY_AP_COURSE_B,INPUT_PULLUP);}

void loop(){

//TESTES ROTARY ENCODERS

ContRTY_AP_VERTSPD = digitalRead(RTY_AP_VERTSPD_A);
if ((RTY_AP_VERTSPD_Antes == LOW) && (ContRTY_AP_VERTSPD == HIGH)) {
if (digitalRead(RTY_AP_VERTSPD_B) == LOW) {
RTY_AP_VERTSPD_Agora--;
Serial.println("B13");}
else {
RTY_AP_VERTSPD_Agora++;
Serial.println("B14");}}
RTY_AP_VERTSPD_Antes = ContRTY_AP_VERTSPD;

ContRTY_AP_ALT = digitalRead(RTY_AP_ALT_A);
if ((RTY_AP_ALT_Antes == LOW) && (ContRTY_AP_ALT == HIGH)) {
if (digitalRead(RTY_AP_ALT_B) == LOW) {
RTY_AP_ALT_Agora--;
Serial.println("B11");}
else {
RTY_AP_ALT_Agora++;
Serial.println("B12");}}
RTY_AP_ALT_Antes = ContRTY_AP_ALT;

ContRTY_AP_HDG = digitalRead(RTY_AP_HDG_A);
if ((RTY_AP_HDG_Antes == LOW) && (ContRTY_AP_HDG == HIGH)) {
if (digitalRead(RTY_AP_HDG_B) == LOW) {
RTY_AP_HDG_Agora--;
Serial.println("A57");}
else {
RTY_AP_HDG_Agora++;
Serial.println("A58");}}
RTY_AP_HDG_Antes = ContRTY_AP_HDG;

ContRTY_AP_IAS = digitalRead(RTY_AP_IAS_A);
if ((RTY_AP_IAS_Antes == LOW) && (ContRTY_AP_IAS == HIGH)) {
if (digitalRead(RTY_AP_IAS_B) == LOW) {
RTY_AP_IAS_Agora--;
Serial.println("B15");}
else {
RTY_AP_IAS_Agora++;
Serial.println("B16");}}
RTY_AP_IAS_Antes = ContRTY_AP_IAS;

ContRTY_AP_COURSE = digitalRead(RTY_AP_COURSE_A);
if ((RTY_AP_COURSE_Antes == LOW) && (ContRTY_AP_COURSE == HIGH)) {
if (digitalRead(RTY_AP_COURSE_B) == LOW) {
RTY_AP_COURSE_Agora--;
Serial.println("A55");}
else {
RTY_AP_COURSE_Agora++;
Serial.println("A56");}}
RTY_AP_COURSE_Antes = ContRTY_AP_COURSE;
}

And... the last one! Codes to Switches and Buttons + Codes to Encoders! Dont works! I want to run it on my Arduino Mega

//DECLARANDO SWITCHES

int SW_BATERIA = 2;
int SW_PAINEL = 3;
int SW_AVIONICS = 4;
int SW_BEACON = 5;
int SW_NAVLIGHTS = 6;
int SW_TAXI = 7;
int SW_LANDLIGHTS = 8;
int SW_GERADOR = 9;
int SW_START = 10;
int SW_PARKING = 11;

//DECLARANDO BOTÕES

const int BT_AP = 12;
int buttonStateBT_AP;
int lastButtonStateBT_AP = HIGH;
long lastDebounceTimeBT_AP = 0;
long debounceDelayBT_AP = 50;

const int BT_AP_FD = 13;
int buttonStateBT_AP_FD;
int lastButtonStateBT_AP_FD = HIGH;
long lastDebounceTimeBT_AP_FD = 0;
long debounceDelayBT_AP_FD = 50;

const int BT_AP_HDG = 14;
int buttonStateBT_AP_HDG;
int lastButtonStateBT_AP_HDG = HIGH;
long lastDebounceTimeBT_AP_HDG = 0;
long debounceDelayBT_AP_HDG = 50;

const int BT_AP_ALT = 15;
int buttonStateBT_AP_ALT;
int lastButtonStateBT_AP_ALT = HIGH;
long lastDebounceTimeBT_AP_ALT = 0;
long debounceDelayBT_AP_ALT = 50;

const int BT_AP_NAV = 16;
int buttonStateBT_AP_NAV;
int lastButtonStateBT_AP_NAV = HIGH;
long lastDebounceTimeBT_AP_NAV = 0;
long debounceDelayBT_AP_NAV = 50;

const int BT_AP_APP = 17;
int buttonStateBT_AP_APP;
int lastButtonStateBT_AP_APP = HIGH;
long lastDebounceTimeBT_AP_APP = 0;
long debounceDelayBT_AP_APP = 50;

const int BT_AP_SPD = 18;
int buttonStateBT_AP_SPD;
int lastButtonStateBT_AP_SPD = HIGH;
long lastDebounceTimeBT_AP_SPD = 0;
long debounceDelayBT_AP_SPD = 50;

const int BT_GPS = 19;
int buttonStateGPS;
int lastButtonStateGPS = HIGH;
long lastDebounceTimeGPS = 0;
long debounceDelayGPS = 50;

const int BT_SYNC = 20;
int buttonStateSYNC;
int lastButtonStateSYNC = HIGH;
long lastDebounceTimeSYNC = 0;
long debounceDelaySYNC = 50;

//DECLARANDO ROTARY ENCODERS

int RTY_AP_VERTSPD_A = A0;
int RTY_AP_VERTSPD_B = A1;
int RTY_AP_VERTSPD_Agora = 0;
int RTY_AP_VERTSPD_Antes = LOW;
int ContRTY_AP_VERTSPD = LOW;

int RTY_AP_ALT_A = A2;
int RTY_AP_ALT_B = A3;
int RTY_AP_ALT_Agora = 0;
int RTY_AP_ALT_Antes = LOW;
int ContRTY_AP_ALT = LOW;

int RTY_AP_HDG_A = A4;
int RTY_AP_HDG_B = A5;
int RTY_AP_HDG_Agora = 0;
int RTY_AP_HDG_Antes = LOW;
int ContRTY_AP_HDG = LOW;

int RTY_AP_IAS_A = A6;
int RTY_AP_IAS_B = A7;
int RTY_AP_IAS_Agora = 0;
int RTY_AP_IAS_Antes = LOW;
int ContRTY_AP_IAS = LOW;

int RTY_AP_COURSE_A = A8;
int RTY_AP_COURSE_B = A9;
int RTY_AP_COURSE_Agora = 0;
int RTY_AP_COURSE_Antes = LOW;
int ContRTY_AP_COURSE = LOW;

void setup(){

// ATIVANDO PORTA SERIAL

Serial.begin(115200);

// ATIVANDO SWITCHES

pinMode(SW_BATERIA, INPUT_PULLUP);
digitalWrite(SW_BATERIA,HIGH);

pinMode(SW_PAINEL, INPUT_PULLUP);
digitalWrite(SW_PAINEL,HIGH);

pinMode(SW_AVIONICS, INPUT_PULLUP);
digitalWrite(SW_AVIONICS,HIGH);

pinMode(SW_BEACON, INPUT_PULLUP);
digitalWrite(SW_BEACON,HIGH);

pinMode(SW_NAVLIGHTS, INPUT_PULLUP);
digitalWrite(SW_NAVLIGHTS,HIGH);

pinMode(SW_TAXI, INPUT_PULLUP);
digitalWrite(SW_TAXI,HIGH);

pinMode(SW_LANDLIGHTS, INPUT_PULLUP);
digitalWrite(SW_LANDLIGHTS,HIGH);

pinMode(SW_GERADOR, INPUT_PULLUP);
digitalWrite(SW_GERADOR,HIGH);

pinMode(SW_START, INPUT_PULLUP);
digitalWrite(SW_START,HIGH);

pinMode(SW_PARKING, INPUT_PULLUP);
digitalWrite(SW_PARKING,HIGH);

//ATIVANDO BOTOES

pinMode(BT_AP, INPUT);
digitalWrite(BT_AP,HIGH);

pinMode(BT_AP_FD, INPUT);
digitalWrite(BT_AP_FD,HIGH);

pinMode(BT_AP_HDG, INPUT);
digitalWrite(BT_AP_HDG,HIGH);

pinMode(BT_AP_ALT, INPUT);
digitalWrite(BT_AP_ALT,HIGH);

pinMode(BT_AP_NAV, INPUT);
digitalWrite(BT_AP_NAV,HIGH);

pinMode(BT_AP_APP, INPUT);
digitalWrite(BT_AP_APP,HIGH);

pinMode(BT_AP_SPD, INPUT);
digitalWrite(BT_AP_SPD,HIGH);

pinMode(BT_GPS, INPUT);
digitalWrite(BT_GPS,HIGH);

pinMode(BT_SYNC, INPUT);
digitalWrite(BT_SYNC,HIGH);

//ATIVANDO ROTARY ENCODERS

pinMode (RTY_AP_VERTSPD_A,INPUT_PULLUP);
pinMode (RTY_AP_VERTSPD_B,INPUT_PULLUP);

pinMode (RTY_AP_ALT_A,INPUT_PULLUP);
pinMode (RTY_AP_ALT_B,INPUT_PULLUP);

pinMode (RTY_AP_HDG_A,INPUT_PULLUP);
pinMode (RTY_AP_HDG_B,INPUT_PULLUP);

pinMode (RTY_AP_IAS_A,INPUT_PULLUP);
pinMode (RTY_AP_IAS_B,INPUT_PULLUP);

pinMode (RTY_AP_COURSE_A,INPUT_PULLUP);
pinMode (RTY_AP_COURSE_B,INPUT_PULLUP);}

void loop(){

delay(1);

//TESTES ROTARY ENCODERS

ContRTY_AP_VERTSPD = digitalRead(RTY_AP_VERTSPD_A);
if ((RTY_AP_VERTSPD_Antes == LOW) && (ContRTY_AP_VERTSPD == HIGH)) {
if (digitalRead(RTY_AP_VERTSPD_B) == LOW) {
RTY_AP_VERTSPD_Agora--;
Serial.println("B13");}
else {
RTY_AP_VERTSPD_Agora++;
Serial.println("B14");}}
RTY_AP_VERTSPD_Antes = ContRTY_AP_VERTSPD;

ContRTY_AP_ALT = digitalRead(RTY_AP_ALT_A);
if ((RTY_AP_ALT_Antes == LOW) && (ContRTY_AP_ALT == HIGH)) {
if (digitalRead(RTY_AP_ALT_B) == LOW) {
RTY_AP_ALT_Agora--;
Serial.println("B12");}
else {
RTY_AP_ALT_Agora++;
Serial.println("B11");}}
RTY_AP_ALT_Antes = ContRTY_AP_ALT;

ContRTY_AP_HDG = digitalRead(RTY_AP_HDG_A);
if ((RTY_AP_HDG_Antes == LOW) && (ContRTY_AP_HDG == HIGH)) {
if (digitalRead(RTY_AP_HDG_B) == LOW) {
RTY_AP_HDG_Agora--;
Serial.println("A58");}
else {
RTY_AP_HDG_Agora++;
Serial.println("A57");}}
RTY_AP_HDG_Antes = ContRTY_AP_HDG;

ContRTY_AP_IAS = digitalRead(RTY_AP_IAS_A);
if ((RTY_AP_IAS_Antes == LOW) && (ContRTY_AP_IAS == HIGH)) {
if (digitalRead(RTY_AP_IAS_B) == LOW) {
RTY_AP_IAS_Agora--;
Serial.println("B16");}
else {
RTY_AP_IAS_Agora++;
Serial.println("B15");}}
RTY_AP_IAS_Antes = ContRTY_AP_IAS;

ContRTY_AP_COURSE = digitalRead(RTY_AP_COURSE_A);
if ((RTY_AP_COURSE_Antes == LOW) && (ContRTY_AP_COURSE == HIGH)) {
if (digitalRead(RTY_AP_COURSE_B) == LOW) {
RTY_AP_COURSE_Agora--;
Serial.println("A55");}
else {
RTY_AP_COURSE_Agora++;
Serial.println("A56");}}
RTY_AP_COURSE_Antes = ContRTY_AP_COURSE;

// Acionamento dos SWITCHES

delay(500);

if(digitalRead(SW_BATERIA)==LOW){
Serial.println("E18");}//SW_ON
else{
Serial.println("E17");}//SW_OFF

if(digitalRead(SW_PAINEL)==LOW){
Serial.println("C461");//SW_ON
Serial.println("C501");}//SW_ON
else{
Serial.println("C460");//SW_OFF
Serial.println("C500");}//SW_OFF

if(digitalRead(SW_AVIONICS)==LOW){
Serial.println("A431");}//SW_ON
else{
Serial.println("A430");}//SW_OFF

if(digitalRead(SW_BEACON)==LOW){
Serial.println("C421");}//SW_ON
else{
Serial.println("C420");}//SW_OFF

if(digitalRead(SW_NAVLIGHTS)==LOW){
Serial.println("C411");//SW_ON
Serial.println("C491");//SW_ON
Serial.println("C451");}//SW_ON
else{
Serial.println("C410");//SW_OFF
Serial.println("C490");//SW_OFF
Serial.println("C450");}//SW_OFF

if(digitalRead(SW_TAXI)==LOW){
Serial.println("C441");}//SW_ON
else{
Serial.println("C440");}//SW_OFF

if(digitalRead(SW_LANDLIGHTS)==LOW){
Serial.println("C431");//SW_ON
Serial.println("C481");//SW_ON
Serial.println("C471");}//SW_ON
else{
Serial.println("C430");//SW_OFF
Serial.println("C480");//SW_OFF
Serial.println("C470");}//SW_OFF

if(digitalRead(SW_GERADOR)==LOW){
Serial.println("E21");//SW_ON
Serial.println("E24");}//SW_ON
else{
Serial.println("E20");//SW_OFF
Serial.println("E23");}//SW_OFF

if(digitalRead(SW_START)==LOW){
Serial.println("E42");//SW_ON
Serial.println("E45");}//SW_ON
else{
Serial.println("E43");//SW_OFF
Serial.println("E46");}//SW_OFF

if(digitalRead(SW_PARKING)==LOW){
Serial.println("C041");}//SW_ON
else{
Serial.println("C040");}//SW_OFF

// Acionamento dos BOTÕES

delay(1);

int readingBT_AP = digitalRead(BT_AP);
if (readingBT_AP != lastButtonStateBT_AP) { // IF1
lastDebounceTimeBT_AP = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP) > debounceDelayBT_AP) { // IF2
if (readingBT_AP != buttonStateBT_AP) { //IF3
buttonStateBT_AP = readingBT_AP;
if (buttonStateBT_AP == HIGH) { // IF4
Serial.println("B01");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP = readingBT_AP;

int readingBT_AP_FD = digitalRead(BT_AP_FD);
if (readingBT_AP_FD != lastButtonStateBT_AP_FD) { // IF1
lastDebounceTimeBT_AP_FD = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_FD) > debounceDelayBT_AP_FD) { // IF2
if (readingBT_AP_FD != buttonStateBT_AP_FD) { // IF3
buttonStateBT_AP_FD = readingBT_AP_FD;
if (buttonStateBT_AP_FD == HIGH) { // IF4
Serial.println("B34"); // FIM IF4
Serial.println("B30");}
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_FD = readingBT_AP_FD;

int readingBT_AP_HDG = digitalRead(BT_AP_HDG);
if (readingBT_AP_HDG != lastButtonStateBT_AP_HDG) { // IF1
lastDebounceTimeBT_AP_HDG = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_HDG) > debounceDelayBT_AP_HDG) { // IF2
if (readingBT_AP_HDG != buttonStateBT_AP_HDG) { //IF3
buttonStateBT_AP_HDG = readingBT_AP_HDG;
if (buttonStateBT_AP_HDG == HIGH) { // IF4
Serial.println("B04");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_HDG = readingBT_AP_HDG;

int readingBT_AP_ALT = digitalRead(BT_AP_ALT);
if (readingBT_AP_ALT != lastButtonStateBT_AP_ALT) { // IF1
lastDebounceTimeBT_AP_ALT = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_ALT) > debounceDelayBT_AP_ALT) { // IF2
if (readingBT_AP_ALT != buttonStateBT_AP_ALT) { //IF3
buttonStateBT_AP_ALT = readingBT_AP_ALT;
if (buttonStateBT_AP_ALT == HIGH) { // IF4
Serial.println("B05");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_ALT = readingBT_AP_ALT;

int readingBT_AP_NAV = digitalRead(BT_AP_NAV);
if (readingBT_AP_NAV != lastButtonStateBT_AP_NAV) { // IF1
lastDebounceTimeBT_AP_NAV = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_NAV) > debounceDelayBT_AP_NAV) { // IF2
if (readingBT_AP_NAV != buttonStateBT_AP_NAV) { //IF3
buttonStateBT_AP_NAV = readingBT_AP_NAV;
if (buttonStateBT_AP_NAV == HIGH) { // IF4
Serial.println("B10");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_NAV = readingBT_AP_NAV;

int readingBT_AP_APP = digitalRead(BT_AP_APP);
if (readingBT_AP_APP != lastButtonStateBT_AP_APP) { // IF1
lastDebounceTimeBT_AP_APP = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_APP) > debounceDelayBT_AP_APP) { // IF2
if (readingBT_AP_APP != buttonStateBT_AP_APP) { //IF3
buttonStateBT_AP_APP = readingBT_AP_APP;
if (buttonStateBT_AP_APP == HIGH) { // IF4
Serial.println("B08");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_APP = readingBT_AP_APP;

int readingBT_AP_SPD = digitalRead(BT_AP_SPD);
if (readingBT_AP_SPD != lastButtonStateBT_AP_SPD) { // IF1
lastDebounceTimeBT_AP_SPD = millis();} // FIM IF1
if ((millis() - lastDebounceTimeBT_AP_SPD) > debounceDelayBT_AP_SPD) { // IF2
if (readingBT_AP_SPD != buttonStateBT_AP_SPD) { //IF3
buttonStateBT_AP_SPD = readingBT_AP_SPD;
if (buttonStateBT_AP_SPD == HIGH) { // IF4
Serial.println("B26");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateBT_AP_SPD = readingBT_AP_SPD;

int readingGPS = digitalRead(BT_GPS);
if (readingGPS != lastButtonStateGPS) { // IF1
lastDebounceTimeGPS = millis();} // FIM IF1
if ((millis() - lastDebounceTimeGPS) > debounceDelayGPS) { // IF2
if (readingGPS != buttonStateGPS) { //IF3
buttonStateGPS = readingGPS;
if (buttonStateGPS == HIGH) { // IF4
Serial.println("A54");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateGPS = readingGPS;

int readingSYNC = digitalRead(BT_SYNC);
if (readingSYNC != lastButtonStateSYNC) { // IF1
lastDebounceTimeSYNC = millis();} // FIM IF1
if ((millis() - lastDebounceTimeSYNC) > debounceDelaySYNC) { // IF2
if (readingSYNC != buttonStateSYNC) { //IF3
buttonStateSYNC = readingSYNC;
if (buttonStateSYNC == HIGH) { // IF4
Serial.println("E33");} // FIM IF4
else{ // ELSE
Serial.println("B17");} // FIM ELSE
} // FIM IF3
} // FIM IF2
lastButtonStateGPS = readingGPS;
}

I hope you can give me some help or a new code working! Thanks folks!