필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Sanjay Yadav
Sanjay Yadav 2017년 2월 1일
댓글: Stephen23 2021년 2월 14일
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.
  댓글 수: 1
Sanjay Yadav
Sanjay Yadav 2017년 2월 2일
Thank you so much sir, it was a silly mistake thanks for pointing out.

댓글을 달려면 로그인하십시오.

추가 답변 (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