Need help to see if the two codes I fused together are correctly placed

1 次查看(过去 30 天)
clear all; close all;
a = arduino('/dev/tty.SLAB_USBtoUART', 'uno')
tic
max_samples = 1000;
tic
for i = 1:max_samples
sound_data(i) = readVoltage(a,'A2')
time_data(i) = toc;
end
plot(time_data, sound_data)
figure
h = animatedline;
ax = gca;
ax.YGrid = 'on';
ax.YLim = [-0.1 5];
title('Sound sensor voltage vs time (live)');
ylabel('Time [HH:MM:SS]');
xlabel('Voltage [volt]');
stop = false;
startTime = datetime('now');
while ~stop
voltage = readVoltage(a,'A2');
t = datetime('now') - startTime;
addpoints(h,datenum(t),voltage)
ax.XLim = datenum([t-seconds(15) t]);
datetick('x','keeplimits')
drawnow
stop = readDigitalPin(a,'D6');
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by