You are on page 1of 2

************************CÓDIGO MATLAB*****************

tarjeta=arduino('COM13','UNO');
disp('Conexión establecida ...');
x=zeros(1,10);
for k=1:10
x(k)=readVoltage(tarjeta,'A5');
pause(0.2);
end
x

***********************************************************

**********************CÓDIGO GUIDE**********************

% --- Executes just before VisorArduino is made visible.


function VisorArduino_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to VisorArduino (see VARARGIN)

% Choose default command line output for VisorArduino


handles.output = hObject;

set(handles.lecturaBoton,'Enable','Off');
set(handles.limpiaBoton,'Enable','Off');
handles.led1.BackgroundColor=[1,0,0];
handles.led2.Enable='Off';
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes VisorArduino wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = VisorArduino_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in cierraBoton.


function cierraBoton_Callback(hObject, eventdata, handles)
% hObject handle to cierraBoton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcbf);

% --- Executes on button press in conectaBoton.


function conectaBoton_Callback(hObject, eventdata, handles)
% hObject handle to conectaBoton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tarjeta=arduino('COM13','UNO');
set(handles.lecturaBoton,'Enable','On');
set(handles.limpiaBoton,'Enable','On');
handles.led1.BackgroundColor=[0,1,0];
handles.led2.Enable='On';
handles.led2.BackgroundColor=[1,0,0];
handles.tar=tarjeta;
guidata(hObject,handles);

% --- Executes on button press in lecturaBoton.


function lecturaBoton_Callback(hObject, eventdata, handles)
% hObject handle to lecturaBoton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=zeros(1,20);
handles.led2.BackgroundColor=[1,0,0];
for k=1:20
x(k)=readVoltage(handles.tar,'A5');
pause(0.2);
end
handles.led2.BackgroundColor=[0,1,0];
plot(x,'*r');
guidata(hObject,handles);

% --- Executes on button press in limpiaBoton.


function limpiaBoton_Callback(hObject, eventdata, handles)
% hObject handle to limpiaBoton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cla(handles.ejes);
handles.led2.BackgroundColor=[1,0,0];

% --- Executes on button press in led1.


function led1_Callback(hObject, eventdata, handles)
% hObject handle to led1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in led2.


function led2_Callback(hObject, eventdata, handles)
% hObject handle to led2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

You might also like