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

1 view (last 30 days)
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

Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!