Breaking a loop GUI?

1 visualizzazione (ultimi 30 giorni)
Amed
Amed il 11 Feb 2013
Reading in accelerometer data in a GUI code. I'm trying to break the loop while reading by using the following code...
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = getappdata(handles.text11, 'text11');
%COMPORT
comPort = '/dev/tty.usbmodemfd121';
%READS SERIAL
[accelerometer.s,serialFlag] = setupSerial(comPort);
calCo = calibrate(accelerometer.s);
%READS DATA
while (a == 0)
if (a == 1)
closeSerial
end
[gx gy gz] = readAcc(accelerometer,calCo);
cla;
r = sqrt((gx^2)+(gy^2)+(gz^2));
r
end
guidata(hObject, handles);
My problem is that the data keeps reading even when (a == 1), which is activated from a separate pushbutton. I've already tested the outputs of both each pushbuttons and they do read 0 and 1, but when reading the data, if I press the 1 pushbutton the data will still read.
  6 Commenti
Amed
Amed il 14 Feb 2013
^Sorry. Anybody else have ideas? I haven't bumped in two days.
Amed
Amed il 14 Feb 2013
Anybody? This is a major assignment help a brother out

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 11 Feb 2013
while true
drawnow;
a = getappdata(handles.text11, 'text11');
if a == 0; break; end
...
end
  2 Commenti
Amed
Amed il 13 Feb 2013
Where in the code would I put this? Thanks
Jan
Jan il 11 Mar 2013
@Amed: Neither "oh ok" nor "anything" contains enough information to understand, if this answer has solved your problem or not. If you want help, provide more details instead of bumping the thread without new informations.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by