Matlab Arduino: Problem with turning on Leds in Sequence

2 次查看(过去 30 天)
Hello
Before anything I just clarify I´m still a noob in matlab. That said Im working in a script wich makes a real time adquisition of some voltage values via the Arduino A0 analog input. Depending on the voltage the leds must turn on in a sequence like a roulete (in circles). The problem is the code im using to turn on the leds
while t<inf
% All the adquisition and plotting code here
if PB(t)<PBC(t) % This is my conditional and works fine
writeDigitalPin(a,'D7',1)
pause(0.5)
writeDigitalPin(a,'D7',0)
writeDigitalPin(a,'D8',1)
pause(0.5)
writeDigitalPin(a,'D8',0)
% And so ON
end
end
The thing is that Im plotting in real time the values and the Pause inside the code is disrupting my adquisition. Is there a way to run the conditionals in paralel with the adquisition script so it doesnt disrupt the plotting? Cause another idea on the way is that when the conditional is not met again to do a "break" and stop the leds from "rotating".
I would be most grateful for any help, idea, hint or clue in this matter.
Thanks to all in advanced for the help

采纳的回答

Abhishek Singh
Abhishek Singh 2019-3-5
Assuming if your condition works properly,
you can tackle the issue by bypassing the pause function and controlling the LED's using flags.
LED1 = false;
LED2 = false
while t<inf
% All the acquisition and plotting code here
if PB(t)<PBC(t) % This is my conditional and works fine
writeDigitalPin(a,'D7',1)
x=datetime;
% And so ON
end
if(datetime-x >1)
writeDigitalPin(a,'D7',1)
end
end
this code will bypass the pause function.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by