Hi! I'm kind of new, but I've been playing with arduino for a few months now. So here's my problem:
I am attempting to make a kind of "program loader" type sketch that will read data from EEPROM or an SD shield and execute it, as a way of extending sketch size. Of course I don't plan on directly writing arduino inside of arduino, just a custom opcode approach.
Enough about the project, though; here's the thing I need advice with. Becuase I'm trying to make it somewhat user-friendly and executed via the serial monitor, I'm trying to have a Serial.read() system that waits for a user response. The problem, of course, is that I don't know of any way of making the system wait until an input is given, so I'm having to do something like this:
label:
Serial.println("prompt 0 or 1");
Serial.println("0 | option a");
Serial.println("1 | option b");
int answer = Serial.read();
//Notice I have "48" and "148." The reasoning behind this is that at the start of a Serial.read() command
//it will put a "1" bundled with the ASCII character sent.
void prompt(String m1,String m2,String m3,int i1,int i2,int o1,int o2){
int a = o1;
int b = o2;
while(!Serial){}
Serial.println(m1);
Serial.println(m2);
Serial.println(m3);
while(!Serial.available()){}
int input = Serial.parseInt();
if(input == i1){
return a;
}else if(input == i2){
return b;
}
}
For some reason it's giving an error on return saying:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"
testytest.ino: In function 'void prompt(String, String, String, int, int, int, int)':
testytest:22: error: return-statement with a value, in function returning 'void' [-fpermissive]
testytest:24: error: return-statement with a value, in function returning 'void' [-fpermissive]
return-statement with a value, in function returning 'void' [-fpermissive]