Blink LED at specify time with Matlab - Arduino
Show older comments
Hi, I want to turn on LED for a given time such as 2 minutes and then it will turn off by using Matlab with Arduino hardware. I already search how to code it but I have no idea how to do it. The code below is my trial.
time = str2num(get(handles.edit3,'String'));
S = seconds(time);
if S > 0
writeDigitalPin(a, 'D13',1);
else
writeDigitalPin(a, 'D13', 0);
end
2 Comments
Jan
on 1 Feb 2018
@melisa: Please mention, how this question is related to Matlab. How is the LED connected to Matlab? Without knowing this detail, an answer would required to guess.
melisa samad
on 1 Feb 2018
Accepted Answer
More Answers (1)
Madhu Govindarajan
on 2 Feb 2018
1 vote
You can use tic and toc for this. When you run tic it starts a stopwatch style timer, you can then use toc to know the elapsed time and use a while loop to check if it is still less than your desired elapsed time.
2 Comments
melisa samad
on 4 Feb 2018
Walter Roberson
on 4 Feb 2018
timelimit = 2*60;
writeDigitalPin(a, 'D13',1);
start = tic;
while toc(start) < timelimit
pause(0.01); %do _something_, even if just a useless computation
end
writeDigitalPin(a, 'D13', 0);
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!