I am trying to run a simple Led On and Off project using arduino and app designer. The program does seem to function however, the code has errors
13 ビュー (過去 30 日間)
古いコメントを表示
This is the code I put under the callbacks for the push buttons:
function LedOnButtonPushed(app, event)
clear all;
global a;
a = arduino;
while(1)
writeDigitalPin(a,'D5',1)
end
end
function LedOffButtonPushed(app, event)
clear all;
global a;
a = arduino;
while(1)
writeDigitalPin(a,'D5',0)
end
end
These are the errors that I receive:
Error using testing/LedOffButtonPushed (line 45)
MATLAB connection to Mega2560 at COM4 exists in your workspace. To create a new connection, clear the existing object.
Error using asyncio.Stream/wait (line 183)
Error while evaluating Button PrivateButtonPushedFcn.
Undefined function 'writeDigitalPin' for input arguments of type 'double'.
Error in testing/LedOnButtonPushed (line 26)
writeDigitalPin(a,'D5',1)
Error while evaluating Button PrivateButtonPushedFcn.
%Your help will be appreciated thank you!
採用された回答
Prateek
2022 年 11 月 21 日
Hi Kekeletso,
The code snippets you have posted seem fine in themselves; perhaps the problem lies in the rest of the code.
For better assistance, I request you to post the app designer file and complete code, so I can assess the source of the error.
Regards,
Prateek
3 件のコメント
Prateek
2022 年 11 月 28 日
Thanks for sharing the code.
I have made some changes, as follows -
a) A private property "connObj" is declared (line 12) and placed in a StartupFcn called "initialize" (line 20). This property stores the Arduino object, which gets created when the app is launched. This ensures that callback functions have access to a single Arduino object.
b) The call back functions for buttons use "connObj" to change the state of "Ledpin". This operation does not need an infinite while loop and hence that has been removed (lines 31 and 38).
The edited app is attached here.
You may also want to refer to the following links for details on app designer-
Hope this helps.
Regards,
Prateek
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!