필터 지우기
필터 지우기

Trying to pause the code until my button is pressed and will continue the code

조회 수: 2 (최근 30일)
Joel Erdmann
Joel Erdmann 2019년 11월 20일
편집: Ridwan Alam 2019년 11월 21일
I want my code to not run until I press a button on my curcuit which will cause DigitalPin('D4') to be 0 and then I want it to run my code.
clear all
clear
clc
a = arduino('com3', 'uno');
s = servo(a, 'D10','MaxPulseDuration', .0025, 'MinPulseDuration', .0005);
readDigitalPin(a,'D2')
n = 200;
x = zeros(1,n);
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

답변 (1개)

Ridwan Alam
Ridwan Alam 2019년 11월 20일
편집: Ridwan Alam 2019년 11월 21일
You can use a while loop to wait:
while(readDigitalPin(a,'D4')!=0)
% wait here
end

카테고리

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