Best practice for using a physical button and Arduino to control a Matlab GUI
Show older comments
I'm working on a matlab app that will be used to control an instrument. One of my requirements is to have a physical button to initiate measurements, but I want to be able to change settings and use the GUI in my app while Matlab waits for a button press.
I have an arduino which interfaces with the button and controls other aspects of the instrument. Most examples use a while loop that polls the status of the button. Polling must be reasonably fast (~60 Hz) to ensure that button presses aren't missed, and that's going to eat up a lot of time on a single-threaded program. Seems like a clunky solution.
I've been taught that the best practice is to have an interrupt service routine to handle button presses like this, and that polling is inconsistent if your software has tasks to perform aside from polling. But, I haven't found any interrupt-like capability in Matlab.
So, what is the best practice initiating an action in Matlab using a physical button?
My current thinking is that I could run a button-polling function using parfeval, so it is running in an independent thread, and then set up a listener in my app to detect when the polling thread detects a change, similar to the suggestion in this thread. I'm figuring out how to implement this now, but help would be appreciated!
This is the first time I've used Matlab to control a physical instrument, so let me know if I'm missing something obvious.
Accepted Answer
More Answers (0)
Categories
Find more on 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!