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, 1 month ago.
Pause and resume code with Button on Nucleo
Hi,
I am very new to nucleo boards and the libraries for them, so I was wondering how to get my nucleo to pause and resume during execution of code. I have a test servo running and I want to be able to pause the execution of this servo wherever the board is at in the code. Right now i am just trying to get the user button to be the input for this, but i can't seem to get it to work properly.
so, to be clear: I want to code my nucleo to run its code like it normally would with an solid on LED until the user button gets pressed. Then the code execution will pause where its at and the LED will go to flashing at 1 Hz indicating that it has paused. Then if the user button gets pressed again, the code resumes where it left off and the LED goes from blinking at 1 Hz to solid on again.
all I've done is create the servo, led, and interrupt objects in the code then make the servo move and try to tinker with the interrupt stuff/LED.
I REALLY appeciate any help you guys can give me for this!
Thanks for your time -MN
2 Answers
9 years, 1 month ago.
A first simple way: your program never pause: it is a permanent loop.
Depending on a condition, the main program calls a "servo" function , or a "blink" function, or activate the corresponding tickler (interrupt)
Try to program this, using a external switch connected between a digital input and the ground (you have to specify a pull-up for this digital input)
With a button it is more complicated with "rebounce " of the button. Look for a code to debounce. Maybe https://developer.mbed.org/users/AjK/code/DebounceIn . There is a lot of information about debouncing, try google
Have fun
I thought about this but if the code is in the middle of the execute statements in the loop and you press the button since it isn't checking the condition the button won't even affect it, will it?
I need the button to affect it immediately and every time when it is pressed
Thanks for the help!
posted by 28 Oct 20159 years, 1 month ago.
I had a similar problem once
this code might help you
Import programButton_input_ext_interrupt
a program with changes the between two states with the press of a button
maybe it helps
have fun