How to run continuously

18 visualizaciones (últimos 30 días)
Iuliu Toma
Iuliu Toma el 2 de Dic. de 2020
Respondida: Walter Roberson el 2 de Dic. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Dic. de 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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by