필터 지우기
필터 지우기

lamp on off in app designer

조회 수: 29 (최근 30일)
Saad Oussaada
Saad Oussaada 2020년 3월 2일
댓글: Saad Oussaada 2020년 3월 3일
hi everyone !! I need a help
I had writen a program in App designer that can turn on or off a lamp with arduino , the probleme is it runs for one time , I want to add a loop but it doesn't work
someone can help me please
this is the program
a = arduino('com8','uno');
b = readDigitalPin(a,'D3');
if b == 1
app.Lamp.Enable = 'on';
else
app.Lamp.Enable = 'off';
end

채택된 답변

Kojiro Saito
Kojiro Saito 2020년 3월 3일
In order to run iteratively, you need to call readDigitalPin in while loop or for loop.
If you want to run specified times, for example, 100 times with an interval of 1 second, add the following in startUpFcn callback.
a = arduino('com8','uno');
iter = 0;
while iter < 100
b = readDigitalPin(a,'D3');
if b == 1
app.Lamp.Enable = 'on';
else
app.Lamp.Enable = 'off';
end
iter = iter + 1;
pause(1);
end
Alternatively, you can use timer class.
If you want to run forever, you can use while loop in startUpFcn callback.
a = arduino('com8','uno');
while true
b = readDigitalPin(a,'D3');
if b == 1
app.Lamp.Enable = 'on';
else
app.Lamp.Enable = 'off';
end
pause(1);
end
You can stop the iteration by Ctrl+C.
  댓글 수: 1
Saad Oussaada
Saad Oussaada 2020년 3월 3일
thank you so much , it is working

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by