MATLAB-Arduino Serial Communication Available Feedback
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eren GÜVEN
am 8 Aug. 2021
Bearbeitet: Eren GÜVEN
am 14 Aug. 2021
Hello, I am connecting to Arduino on MATLAB App Designer. ( port=arduino('COM7','Uno','Libraries','Servo'); ) I want to get feedback when it is connected to Arduino so when the connection is complete. For example, when the connection is complete, the Lamp should turn from red to green. How can I do it ?
Thanks...
0 Kommentare
Akzeptierte Antwort
Shivam Ahuja
am 12 Aug. 2021
It is my understanding that you want to establish a connection and you want to get the feedback whether the connection is successful or not. The following solution will help you to achieve this:
1. Create a private property or member variable for App class to denote a connection flag and set it once Arduino object creation is complete.
properties (Access = private)
IsConnected = false % Initially set to false to denote no connection
end
2. Create the Arduino object in try/catch block and perform digital operation in try/catch itself. If something is wrong with the connection, the Arduino object creation itself will error out and will go to the catch statement and the digital operation will double check the Arduino object connection.
function ConnectButtonPushed(app, event)
try
a = arduino;
app.IsConnected = true;
%digital operation
catch
app.IsConnected = false;
%digital operation
end
end
Refer to the MATLAB App Designer documentation for more information on how to use properties in app class.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!