I am getting an error message when trying to change a color in the GUI through a script file.

1 view (last 30 days)
I created a very simple GUI using GUIDE that contains a push button and a text box. I also created a script file that I am using to read inputs from an Arduino. What I want to happen is when I push a button that is connected to pin 8 of the Arduino I want the push button on the GUI to change colors to red. I am basically using the GUI as a user feedback, not as an input. This is my script file: (titled 'Untitled2')
delete(instrfindall)
clear b;
b = arduino('COM5');
b.pinMode(8, 'INPUT');
b.pinMode(2, 'INPUT');
x = 0;
Change; %this is the name of my GUI '.m' file
fprintf('Go');
while (x == 0)
if (b.digitalRead(8) == 1)
set(handles.pushbutton1,'backgroundcolor','r');
end
x = b.digitalRead(2);
end
fprintf('End');
here are the first lines of output I get:
Attempting connection .............
Analog & Digital I/O + Encoders + Servos (adioes.pde) sketch detected !
Arduino successfully connected !
Go
This means that the connection to the Arduino is good and the program is currently in the 'while' loop, but when I push the button connected to pin 8 I get the following error message:
Struct contents reference from a non-struct array object.
Error in Untitled2 (line 16)
set(handles.pushbutton1,'backgroundcolor','r');
Any help would be greatly appreciated.
Thanks.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jan 2016
Your code does not define "handles"
IF you were using a GUI built in GUIDE, then "handles" would automatically be passed in as the third parameter of your callback function. But you are not using a function, you are using a script and it is not being called through a callback so you should not expect handles to be defined at all.
Sigh. Right after the call to Change; add the line
handles = guidata(gcf);
and you will probably get handles well defined.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Support Package for 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!