Controlling Arduino via Matlab GUI

I'm trying to control a robot via a matlab gui. the problem is I'd like to have arrows pointing left, right, forward, backwards on my gui to control the robot's movements. Two issues:
1. Does matlab have arrow indicators for it's GUI? 2. I only want the respective command ON while I'm holding the arrow key down. When I release the key I want to stop the motion. Is there a way the gui can detect when the arrow is no longer down and issue a command to stop the motor?

 Accepted Answer

Sean de Wolski
Sean de Wolski on 29 Dec 2014
Yes to all questions.
You can specify the CData of a button to be whatever you want. To control up and down of arrow keys, you can set the Figure's 'KeyPressFcn' and 'KeyReleaseFcn' to fire when the key is pressed and released.

More Answers (1)

Marty Rothwell
Marty Rothwell on 29 Dec 2014
I'm still relatively new to Matlab gui's/ Can you explain what you mean by CData?
Thanks, Marty

1 Comment

CData is the color data for the button, i.e. the image on it. You could use an image of an arrow for this pretty easily. I don't happen to have any arrow images handy, so here's a push button with my dog point left/right/up/down.
I = imread('zoey.jpg');
I = I(300:end,50:200,:);
I = imresize(I,[100 100]);
% Down
uicontrol('Style','pushbutton','CData',flip(rot90(I)),...
'Units','normalized','Position',[0.4 0.2 0.2 0.2]);
% Right
uicontrol('Style','pushbutton','CData',I,...
'Units','normalized','Position',[0.6 0.4 0.2 0.2]);
% Up
uicontrol('Style','pushbutton','CData',rot90(I),...
'Units','normalized','Position',[0.4 0.6 0.2 0.2]);
% Left
uicontrol('Style','pushbutton','CData',flip(I,2),...
'Units','normalized','Position',[0.2 0.4 0.2 0.2]);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!