How to Turn LED blinking on and off using Toggle button?

3 次查看(过去 30 天)
On a toggle button callback, I'm doing this:
while button_state == get(hObject,'Max')
writeDigitalPin(a,'D3',1);
writeDigitalPin(a, 'D6' ,0);
pause(.5);
writeDigitalPin(a,'D3',0);
writeDigitalPin(a, 'D6' ,1);
pause(.5);
end
if button_state == get(hObject,'Min')
writeDigitalPin(a, 'D3' ,0);
writeDigitalPin(a, 'D6' ,0);
end
Now problem is once LED starts blinking, they wont stop and blink continuously, even after I turn toggle button "off". Help me solving the logic.

采纳的回答

Image Analyst
Image Analyst 2017-2-1
You're not updating button_state inside the loops. You need to do that
while button_state == handles.btnToggle.Max
writeDigitalPin(a,'D3',1);
writeDigitalPin(a, 'D6' ,0);
pause(.5);
writeDigitalPin(a,'D3',0);
writeDigitalPin(a, 'D6' ,1);
pause(.5);
% Update button status
button_state = handles.btnToggle.Value; % Or however you get it.
end
Same for the other while loop.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by