【发布时间】:2014-01-27 22:10:11
【问题描述】:
我正在为一个电路工程项目将 MATLAB 与 Arduino 连接起来。我想轮询 Arduino 以了解它在给定传感器上感应到的电压,将该电压添加到向量中,然后将其全部绘制在同一个 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
【问题讨论】:
标签: matlab