how can create Changing lamp color with start and stop button

5 ビュー (過去 30 日間)
Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2022 年 4 月 21 日
回答済み: Amir Azadeh Ranjbar 2022 年 5 月 6 日

採用された回答

Geoff Hayes
Geoff Hayes 2022 年 4 月 21 日
@Amir Azadeh Ranjbar - you would need callback functions for your start and stop buttons. These callbacks would then change the colour of the lamp. Something like the following may work:
% Button pushed function: StartButton
function StartButtonPushed(app, event)
app.Lamp.Color = 'b'; % blue
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
app.Lamp.Color = 'r'; % red
end
  1 件のコメント
Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2022 年 5 月 6 日
Sorry for being late
Thank you for your guidance
But I solved the problem

サインインしてコメントする。

その他の回答 (1 件)

Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2022 年 5 月 6 日
app.Lamp_2.Color='g';
d=app.UITable.Data;
if height(d)<1
t={'','','','','',''};
app.UITable.Data=[d;t];
end
app.t1=datetime("now");
app.Lamp.Color=[1 0 0];
function ChangeA(x,y)
C=app.Lamp.Color;
if isequal(C,[0 1 0])
app.Lamp.Color=[1 0 0];
else
app.Lamp.Color=[0 1 0];
end
end
app.Timer0=timer("TimerFcn",@(x,y) ChangeA,"StartFcn",@ChangeA,"ExecutionMode","fixedRate","Period",0.5);
Sec=1/24/60/60;
startat(app.Timer0,now+1*Sec)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by