How can matlab understand that the external button is pressed or not?

8 ビュー (過去 30 日間)
Nazanin Fazelnia
Nazanin Fazelnia 2018 年 12 月 12 日
コメント済み: Madhu Govindarajan 2018 年 12 月 14 日
Hi,
I want to rotate the servo motor using Arduino Uno, Matlab 2017b and with an external push button. So it's a matter of servo control with Arduino through Matlab. What I have written is attached. It doesn't have any bugs but I cannot reach the desired result, it prints just "The button is not pressed".
The logic of my code is that at first the button is not pressed and then when it is pressed some counter is responsible for next ifs. When the button is pressed for the first time, the counter will be equal to 1 and shaft must rotate according to the code. After that, we have unpressed button and again Button ==0. After pressing again, the value of counter will be 2 and the next tasks. But it doesn't work.
What is wrong with this code?
Thank you in advance.

回答 (2 件)

madhan ravi
madhan ravi 2018 年 12 月 12 日
  6 件のコメント
Nazanin Fazelnia
Nazanin Fazelnia 2018 年 12 月 12 日
Yeah I have.
You mean I have to write these commands in Arduino and then run my code? Does Matlab understand through this way or should I write there also something?
Thank you.
Nazanin Fazelnia
Nazanin Fazelnia 2018 年 12 月 14 日
And also I realized that Matlab and Arduino code cannot use the board simultaneously; when it is active in Matlab code, then I have this error in Arduino that it has problem uploading to the board. So how can it be possible to send a message to Matlab?
Thank you.

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


Madhu Govindarajan
Madhu Govindarajan 2018 年 12 月 13 日
You will have to do this in while loop instead of if else. For an example see this video and if that is what you need the link to download the code is on the same page - https://www.mathworks.com/videos/plotting-live-data-of-a-temperature-sensor-using-arduino-and-matlab-121317.html
  2 件のコメント
Nazanin Fazelnia
Nazanin Fazelnia 2018 年 12 月 14 日
How is it related to what I want?
Thank you.
Madhu Govindarajan
Madhu Govindarajan 2018 年 12 月 14 日
It shows how to read a push button data and stop a while loop based on that. Inside that while loop you can do your servo control instead of the read analog values that the video shows.
Please peruse the links that community members provide and ask clarifying questions as they do this on their spare time.

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

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by