Regarding using a function to control a servo motor via Arduino

2 次查看(过去 30 天)
I am currently to create a function that allows me to control a servo motor (Hitech HS55) via an Arduino Uno board. The function (named 'motor') and code are as shown below.
Screenshot 2018-12-27 at 4.03.56 PM.png
However, whenever I execute the function, all it does is give me the value of the position of the motor and the value of y, yet the servo motor does not turn nor respond.
On the other hand, when I copy and paste the same text onto the command window and execute it, the servo motor will respond.
Why does the servo motor not respond when the function is executed?
Thank you.

回答(2 个)

Walter Roberson
Walter Roberson 2018-12-27
create the arduino object outside of the function and pass it in. You do not want to have multiple connections and the initialization of the object is expensive as it has to synchronise communication each time.

madhan ravi
madhan ravi 2018-12-27
编辑:madhan ravi 2018-12-27
I believe the communication between the servo and the arduino is not set right.

社区

更多回答在  Power Electronics Control

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by