MATLAB Answers

GUI interface with arduino

조회 수: 123(최근 30일)
Tee
Tee 2011년 3월 24일
댓글: Mohamed Asif 2017년 7월 6일
now, i try to control arduino board through Matlab GUI(using IO packages). First,i try to light on the LED by click on the push button i create, below is the callback function i put:
a=arduino('com3')
a.pinMode(10,'output');
a.digitalWrite(10,1);
after i try it, the LED only blink for a second, but now i wish to light on the LED continuously, what code should i type? I wish to light on and light off the LED using push button i create...anyone can help me, thanks..
  댓글 수: 1
Mohamed Asif
Mohamed Asif 2017년 7월 6일
https://in.mathworks.com/videos/arduino-and-matlab-reading-inputs-and-writing-outputs-106502.html
use this above link you can get idea about it

댓글을 달려면 로그인하십시오.

채택된 답변

Jarrod Rivituso
Jarrod Rivituso 2011년 3월 24일
Disclaimer - I've used Arduinos in the past, but never used the MATLAB Arduino package.
With that said, I'm not sure if this is your issue, but one thing to consider is whether you want your callback to reinitialize the Arduino pinmode every time.
It seems to me like you'd really want to set up the Arduino pin modes and COM ports in the GUI initialization, and then have your callback only perform the digitalWrite.
If using GUIDE, then you will find a GUI initialization function that you can use to do the initialization. Then, you can use the guidata function to add the Arduino object to the guidata. Something like...
a = arduino('com3');
a.pinMode(10,'output');
handles.a = a;
guidata(hObject, handles);
Then, you could use the handles structure again in your callback
handles.a.digitalWrite(10,ledValue)
Again, this is all assuming you are using GUIDE. If you aren't, then you probably know your GUI's initialization better than I do.
  댓글 수: 3
medo
medo 2014년 7월 28일
hi all .... please i need the correct arduinoIO because iam downloading it but it not woke >>> thanx to all

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Kaustubha Govind
Kaustubha Govind 2011년 3월 24일
You could try using a persistent variable to store that last state, and toggle that each time the callback is fired:
persistent ledValue
if isempty(ledValue)
ledValue = 0;
end
ledValue = ~ledValue; %toggle ledValue
a=arduino('com3');
a.pinMode(10,'output');
a.digitalWrite(10,ledValue);
  댓글 수: 3
heisenberg
heisenberg 2015년 3월 18일
how to access serial pins in above program to send data?

댓글을 달려면 로그인하십시오.


hardik sanghvi
hardik sanghvi 2015년 11월 25일
How to make pause and counter button code

태그

Community Treasure Hunt

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

Start Hunting!

Translated by