Effacer les filtres
Effacer les filtres

i believe there may be a problem with entering my switch case

2 vues (au cours des 30 derniers jours)
Jake
Jake le 25 Mai 2023
i am using this code to read a value from the moisture sensor and light up an led depending on the moisuture. however when i run this code it makes it as far as reading the moisture value and not doing anything else. any help at all would be greatly appreciated
code for reference:
clear
clc
a = arduino();
PB = 'D8';
key = readDigitalPin(a,PB);
pbc = 0;
b = mod(pbc, 3);
moisture = readVoltage(a,"A0")
while true
switch b
case 0
if moisture >= 4 && moisture <= 5
writeDigitalPin(a,'D2',1) % green
writeDigitalPin(a,'D4',0) % orange
writeDigitalPin(a,'D7',0) % red
%writePWMVoltage(a, 'D11',1.67)
pause(5)
writePWMVoltage(a, 'D11',0 )
pause(120)
else
writeDigitalPin(a,'D2',1) % green
end
case 1
if moisture >= 3 && moisture <= 4
writeDigitalPin(a,'D2',1) % green
writeDigitalPin(a,'D4',0) % orange
writeDigitalPin(a,'D7',0) % red
%writePWMVoltage(a, 'D11',1.67)
pause(5)
writePWMVoltage(a, 'D11',0 )
pause(120)
else
writeDigitalPin(a,'D2',1) % green
end
case 2
if moisture >= 2 && moisture <= 3
writeDigitalPin(a,'D2',1) % green
writeDigitalPin(a,'D4',0) % orange
writeDigitalPin(a,'D7',0) % red
% writePWMVoltage(a, 'D11',1.67)
pause(5)
writePWMVoltage(a, 'D11',0 )
pause(120)
else
writeDigitalPin(a,'D2',1) % green
end
end
if key == 1
pbc = pbc + 1;
end
end

Réponses (1)

Alexander
Alexander le 25 Mai 2023
Shouldn't be
moisture = readVoltage(a,"A0")
not also in the while-loop?

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Tags

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by