フィルターのクリア

How to end loop if value does not change for 10 consecutive seconds

2 ビュー (過去 30 日間)
Gianluca Finotti
Gianluca Finotti 2018 年 2 月 13 日
コメント済み: Gianluca Finotti 2018 年 2 月 20 日
Hi, I am collecting data from a potentiometer connected to an Arduino. In the script, I tell matlab to keep collecting data for 2 minutes. But I need to tell it that if the user does not move the potentiometer for 10 consecutive seconds, then it should stop the loop and move to the next session (write the data to an excel file). Does anybody have ideas on how to achieve this?
Thank you in advance.

回答 (1 件)

Madhu Govindarajan
Madhu Govindarajan 2018 年 2 月 13 日
編集済み: Madhu Govindarajan 2018 年 2 月 13 日
Here is a potential loop that you can use (with some changes here and there) -
a = arduino;
flag = true;
prevVal = 0;
count = 0;
while flag
val = readVoltage(a,'your pin number here');
if abs(val - prevVal) < eps % You can change the eps value to something reasonable based on what you see.
count = count + 1;
else
count = 0;
end
if count == 10
flag = false;
end
prevVal = val;
end
  1 件のコメント
Gianluca Finotti
Gianluca Finotti 2018 年 2 月 20 日
Hi, I ended up using a similar approach, but this looks like it could work all the same =)
Thank you very much, I really appreciate.

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

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by