0
我MATLAB接口與一個Arduino的電路工程密謀改變向量。我想輪詢Arduino在給定傳感器上感應到的電壓,將該電壓添加到一個矢量,然後將它全部繪製在同一個循環內。我有前兩個部分,但我似乎無法弄清楚如何反覆繪製電壓矢量,因爲它變得更長。有沒有辦法做到這一點?MATLAB在while循環
%{
Ventilation Rate Sensor v0.1
This program uses a thermistor connected to pin A0 and analyzes the
difference in voltage drop in order to assess the user's ventilation rate.
Designed for use with a voltage divider using a 2.2kOhm resistor and a
10kOhm (at 25C) thermistor in series. Note that this REQUIRES the Arduino
to have the code for MATLAB interface already installed. This is included
in the MATLAB Arduino software page at
<<http://www.mathworks.com/matlabcentral/fileexchange/
32374-matlab-support-package-for-arduino-aka-arduinoio-package>>
%}
clc
clear
close all
ard = arduino('COM3');
voltage = [];
timer = datenum(clock+[0,0,0,0,0,30]);
while datenum(clock) < timer
sensorValue = ard.analogRead(0);
voltage = [voltage (sensorValue * (5/1023))];
hold on;
t = [1:1:length(voltage)];
plot(t,voltage)
end
謝謝!這工作得很好。 – SciurusDoomus
@SciurusDoomus很高興幫助。另外,請參閱編輯答案與另一個可能有用的想法 –
有趣。我並不需要削減運行時間,因爲繪圖比我想要輸出的實際數據更像是一種測試機制。但是,我相信我將來需要它,或者讓這個程序在真正舊的系統上可用。謝謝! – SciurusDoomus