i believe there may be a problem with entering my switch case
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Alexander
am 25 Mai 2023
Shouldn't be
moisture = readVoltage(a,"A0")
not also in the while-loop?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!