MATLAB: GUI interface with arduino

arduinoled

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..

Best Answer

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.
Related Question