problem with code for arduino voltage reading
조회 수: 5 (최근 30일)
이전 댓글 표시
Muhammad Alief Nasarudin
2020년 1월 2일
댓글: Muhammad Alief Nasarudin
2020년 1월 6일
Doing a project with pulse sensor on arduino followed a code online it hit an error im unable to understand im still learning matlab at a basic level can anyone help this is the coding error
Undefined function 'readVoltage' for input arguments of type 'matlab.graphics.axis.Axes'.
Error in mypulsesensor (line 85)
data(i) = readVoltage(a,'A0'); % read voltage on pin A0, store as next data point
댓글 수: 2
Geoff Hayes
2020년 1월 2일
Muhammad - what is variable a in your
data(i) = readVoltage(a,'A0')
? The error message is suggesting that this may be an axes and not the arduino (which you are trying to read from). You may need to post more of your code so that we can see how you have defined variables for the axes and arduino.
채택된 답변
Geoff Hayes
2020년 1월 2일
Muhammad - the problem is with this line of code
a = gca;
where you overwrite the arduino assigned variable with the current axes...and so when you reference a again with
data(1) = readVoltage(a,'A0');
the error occurs because now a is the axes. Consider an alternative name for the axes variable (one that perhaps describes what it references)
hCurrentAxes = gca;
plot(time(i-1:i), data(i-1:i)); %draw the line from the last Vout value to the current Vout value
%actual scroller
%Set appropriate axis limits and settings
set(gcf, 'doublebuffer', 'on');
%Avoiding flickering when updating
set(hCurrentAxes,'xlim',[0 dx]);
set(hCurrentAxes,'ylim',[min(50) - 1, max(200) + 1]); %REMEMBER TO CHANGE X AND Y
%Generate constants for use in UI Control intialization
pos = get(hCurrentAxes, 'position');
or just use gca instead.
You could also rename the variable for the arduino "handle" to something that is more descriptive.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!