Hello i’m doing a school project that is supposed to print data to the system monitor and based on that data do different things. The device has 17 buttons attached to it. I want to be able to press 9 buttons in a row in any order and after every press i would like to have the numbers printed out to the serial monitor. The problem is that it doesn’t want to execute the code in the function. It only gets to the point where it prints out “in the function”.
Here is the code
#include <VirtualWire.h>
const int output1 = 38;
const int output2 = 40;
const int output3 = 42;
const int output4 = 44;
const int output5 = 46;
const int output6 = 48;
const int output7 = 50;
const int output8 = 52;
const int output9 = 23;
const int output10 = 25;
const int output11 = 27;
const int output12 = 29;
const int output13 = 31;
const int output14 = 33;
const int output15 = 35;
const int output16 = 53;
const int output17 = 39;
int check_output1 = 0;
int check_output2 = 0;
int check_output3= 0;
int check_output4 = 0;
int check_output5 = 0;
int check_output6 = 0;
int check_output7 = 0;
int check_output8 = 0;
int check_output9 = 0;
int check_output10 = 0;
int check_output11 = 0;
int check_output12 = 0;
int check_output13 = 0;
int check_output14 = 0;
int check_output15 = 0;
int check_output16 = 0;
int check_output17 = 0;
void setup()
{
Serial.begin(9600);
pinMode(output1, INPUT);
pinMode(output2, INPUT);
pinMode(output3, INPUT);
pinMode(output4, INPUT);
pinMode(output5, INPUT);
pinMode(output6, INPUT);
pinMode(output7, INPUT);
pinMode(output8, INPUT);
pinMode(output9, INPUT);
pinMode(output10, INPUT);
pinMode(output11, INPUT);
pinMode(output12, INPUT);
pinMode(output13, INPUT);
pinMode(output14, INPUT);
pinMode(output15, INPUT);
pinMode(output16, INPUT);
pinMode(output17, INPUT);
}
void loop()
{
check_output17=digitalRead(output17);
if(check_output17 == HIGH){
Serial.println("going into function");
number();
}
}
void number(void)
{
check_output1=digitalRead(output1);
check_output2=digitalRead(output2);
check_output3=digitalRead(output3);
check_output4=digitalRead(output4);
check_output5=digitalRead(output5);
check_output6=digitalRead(output6);
check_output7=digitalRead(output7);
check_output8=digitalRead(output8);
check_output9=digitalRead(output9);
check_output10=digitalRead(output10);
check_output11=digitalRead(output11);
check_output12=digitalRead(output12);
check_output13=digitalRead(output13);
check_output14=digitalRead(output14);
check_output15=digitalRead(output15);
check_output16=digitalRead(output16);
Serial.println("in the function");
for(int i = 0; i < 9; i++){
back:
if (check_output1 == HIGH){
Serial.println("1 ");
}
else if (check_output2 == HIGH){
Serial.println("2 ");
}
else if (check_output3 == HIGH){
Serial.println("3 ");
}
else if (check_output4 == HIGH){
Serial.println("A ");
}
else if (check_output5 == HIGH){
Serial.println("4 ");
}
else if (check_output6 == HIGH){
Serial.println("5 ");
}
else if (check_output7 == HIGH){
Serial.println("6 ");
}
else if (check_output8 == HIGH){
Serial.println("B ");
}
else if (check_output9 == HIGH){
Serial.println("7 ");
}
else if (check_output10 == HIGH){
Serial.println("8 ");
}
else if (check_output11 == HIGH){
Serial.println("9 ");
}
else if (check_output12 == HIGH){
Serial.println("C ");
}
else if (check_output13 == HIGH){
Serial.println("* ");
}
else if (check_output14 == HIGH){
Serial.println("0 ");
}
else if (check_output15 == HIGH){
Serial.println("# ");
}
else if (check_output16 == HIGH){
Serial.println("D ");
}
else{
goto back; }
}
}
however when i delete the function and put the code from the deleted function into void loop it somehow works
void loop()
{
check_output1=digitalRead(output1);
check_output2=digitalRead(output2);
check_output3=digitalRead(output3);
check_output4=digitalRead(output4);
check_output5=digitalRead(output5);
check_output6=digitalRead(output6);
check_output7=digitalRead(output7);
check_output8=digitalRead(output8);
check_output9=digitalRead(output9);
check_output10=digitalRead(output10);
check_output11=digitalRead(output11);
check_output12=digitalRead(output12);
check_output13=digitalRead(output13);
check_output14=digitalRead(output14);
check_output15=digitalRead(output15);
check_output16=digitalRead(output16);
check_output17=digitalRead(output17);
if(check_output17 == HIGH){
Serial.println("in function");
delay(1000);
}
if (check_output1 == HIGH){
Serial.println("1 ");
delay(500);}
else if (check_output2 == HIGH){
Serial.println("2 ");
delay(500); }
else if (check_output3 == HIGH){
Serial.println("3 ");
delay(500); }
else if (check_output4 == HIGH){
Serial.println("A ");
delay(500); }
else if (check_output5 == HIGH){
Serial.println("4 ");
delay(500); }
else if (check_output6 == HIGH){
Serial.println("5 ");
delay(500); }
else if (check_output7 == HIGH){
Serial.println("6 ");
delay(500); }
else if (check_output8 == HIGH){
Serial.println("B ");
delay(500); }
else if (check_output9 == HIGH){
Serial.println("7 ");
delay(500); }
else if (check_output10 == HIGH){
Serial.println("8 ");
delay(500); }
else if (check_output11 == HIGH){
Serial.println("9 ");
delay(500);}
else if (check_output12 == HIGH){
Serial.println("C ");
delay(500); }
else if (check_output13 == HIGH){
Serial.println("* ");
delay(500); }
else if (check_output14 == HIGH){
Serial.println("0 ");
delay(500); }
else if (check_output15 == HIGH){
Serial.println("# ");
delay(500); }
else if (check_output16 == HIGH){
Serial.println("D ");
delay(500); }
}
Can anyone explain why the first way doesn’t work and tell me how to fix it?
The reason i want to have a separate function for this is because i plan on expanding the code to do different things. Keep in mind i am a beginner so if manageable please explain in the easiest way possible.
Thank You for your time