Trying to make my code proceed and stop when a button is pressed. Then repeat the actions continuously until I press the button telling it to stop.

6 次查看(过去 30 天)
Below is my code. Right now it starts when I press my button and then record data for a given time interval set by me before hand. I would like to make my code start recording when I press my button on the circuit, then I would like it to record the data from the voltage and stop whenever I press the button to make readDigitalPin(a,'D2') = 0. Once the button is pressed it will stop the recording process and then perform what was recorded onto my servos. I would also like it to continulally to perform the actions infintiy until I press the button again telling it to stop. Thanks.
clear all
clear
clc
a = arduino('com3', 'uno');
s = servo(a, 'D10','MaxPulseDuration', .0025, 'MinPulseDuration', .0005);
b = 6
readDigitalPin(a,'D2')
n = 200;
x = zeros(1,n);
k = 1
while k == 1
false
if readDigitalPin(a,'D2') == 0
break
end
for k = 1:n
z = readVoltage(a,'A5');
p = ((1023 / 5) * z);
x(k) = (p / 1023);
writePosition(s,x(k));
end
for k = 1:n
writePosition(s,x(k))
end
end

回答(0 个)

类别

Help CenterFile 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!

Translated by