How to run continuously
조회 수: 16 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!