How to run continuously

조회 수: 16 (최근 30일)
Iuliu Toma
Iuliu Toma 2020년 12월 2일
답변: Walter Roberson 2020년 12월 2일
Hello. I am trying to make this repeat so that it constantly reads the voltage and updates so that writedigitalpin will start or stop automatically. How can I do this?
if readVoltage(a,'A1') >= 2
writeDigitalPin(a,'D2',1);
elseif readVoltage(a,'A1') < 2
writeDigitalPin(a,'D2',0);
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 2일
current_state = 0;
writeDigitalPin(a,'D2',current_state);
while true
if readVoltage(a, 'A1') >= 2
if current_state == 0; writeDigitalPin(a,'D2',1); end
current_state = 1;
else
if current_state == 1; writeDigitalPin(a,'D2',0); end
current_state = 0;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Converters (High Power)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by