loop in realtime arduino reading

조회 수: 2 (최근 30일)
john white
john white 2019년 3월 22일
댓글: john white 2019년 4월 7일
Hi
I want to read a value of the variable each 0.02 seconds I write this code:
c(1)=readCount(encoder);
for i=2:100
c(i)=readCount(encoder)
pause(0.02)
end
actually I want to read the count of the encoder for the loop (i=2:100)
each 0.02 secound

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 23일
Use a timer object with FixedRate . Be sure to pre-allocate c.
You might have some difficulty reaching 50 readings per second over the USB connection, unless you use a bit of code or a sketch on the arduino side to keep sending out the values instead of waiting for general commands. It is not uncommon for people to report they only get about 40 samples per second unless they run more dedicated code on the arduino.
  댓글 수: 10
john white
john white 2019년 4월 6일
please help I have no idea about the TimerFcn to do my purpose!
john white
john white 2019년 4월 7일
any way, thank you so much Walter Roberson for your help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB 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