필터 지우기
필터 지우기

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

조회 수: 8 (최근 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
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
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 CenterFile 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!

Translated by