Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 7 months ago.
What's wrong of my code ver3
Hi guys i am coming here again for asking you the last question(i am sure).
That is, base on the last version of my code, this time I want to add a menu which can let user return to the main manu for another choice.
here is my code: /media/uploads/Oneoftherulingparty/-1.cpp
it works the first time but after the second choice the returnmenu function comes so quickly thus there is no enough time to display the waveform.
Could you pls help me or provide another solution for my aim?
thanks a lot.
1 Answer
9 years, 7 months ago.
The short answer is to not run the returnmenu function on a ticker, run it only when you want the user to pick again.
bool returnMenu(void); int main() { do { getOption(); // get user option sample20kHz_tick.attach_us(&sample20kHz_task, 50); //attach task to 50us tick wait(15); // run for 15 seconds sample20kHz_tick.detach(); //Stop the filter. } while (returnMenu()); // ask the user if they want to run again. } //------------------------------------------------------------------[returnmenu function] bool returnMenu(void) { int return0 = 0; while(true) { pc.printf("Press button '1' to return the main menu \n\r"); pc.printf("Press button '2' to exit this program \n\r"); pc.scanf("%d", &return0); if (return0 == 1) return true; else if (return0 == 2) return false; else pc.printf("Please type effective number! \n\r"); } }
Or if instead of running for 15 seconds you want to run until they hit a key replace the wait(15) with
while(pc.readable()) // flush any remaining characters from the serial port buffer by reading them pc.getc(); pc.getc(); // now wait until we get a new character