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?

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 29 de Dic. de 2014

0 votos

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.

Más respuestas (1)

Marty Rothwell
Marty Rothwell el 29 de Dic. de 2014

0 votos

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

1 comentario

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]);

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Dic. de 2014

Comentada:

el 29 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by