UPDATE DATA every 5 sec
2 ビュー (過去 30 日間)
古いコメントを表示
I have a ekg sensor attached which reads the heart rate and i have written the code to display Beats per minute based on it. How can add code so that it reads data every 5 seconds and save BPM.
2 件のコメント
mbvoyager
2018 年 9 月 6 日
編集済み: mbvoyager
2018 年 9 月 6 日
I do not really understand your issue.
But a very quick and very very dirty solution could be to use a for or while loop and input the function pause or wait.
This is far from exact in timing but it can limit the readings of your data to a certain coarse interval.
In general it might be a good idea if you look into the usage of timers. Can be found in: timer class.
回答 (1 件)
mbvoyager
2018 年 9 月 6 日
Look into the examples of
With the timer class it is possible to call a function in certain time intervals.
Here is a minimal working example exactly from the help page of the timer class:
t = timer;
t.StartFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.TimerFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.StopFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.Period = 5; % 5 seconds interval executing TimerFcn
t.TasksToExecute = 3; % 3 total calls excecuting TimerFcn
t.ExecutionMode = 'fixedRate';
start(t)
The output will be:
StartFcn executed 06-Sep-2018 14:15:03.161
TimerFcn executed 06-Sep-2018 14:15:03.161
TimerFcn executed 06-Sep-2018 14:15:05.162
TimerFcn executed 06-Sep-2018 14:15:07.161
StopFcn executed 06-Sep-2018 14:15:07.168
After that to delete the timer object
delete(t)
I hope this can help you.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!