How to run continuously

18 visualizzazioni (ultimi 30 giorni)
Iuliu Toma
Iuliu Toma il 2 Dic 2020
Risposto: Walter Roberson il 2 Dic 2020
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

Risposta accettata

Walter Roberson
Walter Roberson il 2 Dic 2020
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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by