Making STOP - Button
Afficher commentaires plus anciens
Hi everybody! I'm new here and have a question about GUI's.
I have a GUI which contains (among other things) two (push)buttons. The first one is a "Start" button and the second one should be some kind of a "Stop" button. By pressing "Start" an infinite loop begins and the program starts reading a certain amount of data from a port and saves it to a file. When it finished reading it waits a few seconds and starts reading again. This happens x times, where x is a predifined value.
Now I want, that pressing the "Stop"-Button forces the program to stop at n < x runs (n depending on when I press the button).
For that purpose I defined a variable "run", which is 1 and gets 0, when "Stop" is pressed. So an exit is possible.
That's the plan. Unfortunatelly that doesn't work. I assume, that the rest of the GUI is "frozen" while the program is stuck in the loop, so pressing "Stop" doesn't change anything. I supposed pressing the button triggers some kind of interrupt, so being stuck in the loop is no problem, but sadly it seems as I am wrong (or I have to enable the interrupt, without knowing how). I already read a related post, where the questioner was advised to use a checkbox instead, but sadly this is no option for my purpose.
I hope some of you can help me? :)
Thank you!
1 commentaire
Antonio De lavalle
le 22 Avr 2021
Déplacé(e) : Rik
le 4 Mar 2023
excuse a doubt I need to make a music note player but they also ask me to incorporate a pause button in the program
Réponse acceptée
Plus de réponses (1)
Rik
le 20 Juil 2018
I use a uicontrol togglebutton in such cases:
%in your looping code:
if get(handles.togglebutton,'Value')
break
end
%in the callback of the button:
set(hObject,'Value',1)
2 commentaires
noNickame
le 23 Juil 2018
Rik
le 23 Juil 2018
You indeed need to reset the togglebutton value when you start your code. You could use a normal pushbutton instead, but that means that you need to be very careful where you load and reload your guidata.
So at the start of you looping function (before you enter the loop), you'll need to set(handles.togglebutton,'Value',1), and then it should work.
PS you see why I don't use GUIDE: a forest of functions calling each other in a convoluted way. Really difficult to understand where you should make changes.
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!