How to run continuously

15 次查看(过去 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

采纳的回答

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 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by