Arduino - Matlab

2 Ansichten (letzte 30 Tage)
Tee
Tee am 21 Mär. 2011
Beantwortet: Shamnad am 31 Okt. 2014
currently i use IO package for Matlab, i can light on LED by using digitalWrite function, but now i wan try to blink the LED but don't know how to do it, can someone help me?

Akzeptierte Antwort

Kaustubha Govind
Kaustubha Govind am 21 Mär. 2011
You can check the elapsed time and toggle the output written to the LED every few seconds.
(It is not clear whether you are using the Simulink Arduino target, or something else here. If this answer doesn't help, please provide more information)
  2 Kommentare
Tee
Tee am 24 Mär. 2011
i didnt use simulink arduino target, just using IO packages, is possible i blink the LED without using it?
Kaustubha Govind
Kaustubha Govind am 24 Mär. 2011
I'm not familiar with the IO package - does it let you read the clock on the Arduino? If yes, you can continuously poll the clock time and toggle every few seconds (maybe take the modulus of the time, and toggle the output value when it reaches a certain value).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Shamnad
Shamnad am 31 Okt. 2014
It's not that hard. Check out the below code if you're using MATLAB Support for Arduino (aka ArduinoIO Package)
% code
% ArduinoIO code for Blinking LED
% Connect to Arduino
MyArduino = arduino('COM1');
% Specify Pin Mode
MyArduino.pinMode(13, 'output');
for i = 1:10
% LED on
MyArduino.digitalWrite(13,1);
% Delay for LED on time
pause(.5);
% LED off
MyArduino.digitalWrite(13,0);
% Delay for LED off time
pause(.5);
end
% Close session
delete(MyArduino);
Or else, if you're using MATLAB Support Package for Arduino Hardware Try the below code. Hope this helps.
% code
% Arduino MATLAB Support Package code for Blinking LED
% Connect to Arduino
MyArduino = arduino('COM1', 'UNO');
for i = 1:10
% LED on
writeDigitalPin(MyArduino,13,1);
% Delay for LED on time
pause(.5);
% LED off
writeDigitalPin(MyArduino,13,0);
% Delay for LED off time
pause(.5);
end
clear MyArduino;

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by