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

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

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

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Tag

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by