III.3.4.capteur de pression :
Une sonde de pression (ou capteur de pression)
est un dispositif destiné à convertir les variations de pression
en variations de tension électrique.
Lorsque la sonde est reliée à un système
numérique, les variations analogiques sont d'abord converties en signaux
numériques binaires par un convertisseur analogique-numérique
avant d'être transmises à l'ordinateur de contrôle et de
gestion.
L'unité de pression fournie par la sonde peut être
exprimée en différentes unités, telle que bar, pascal.
CHAPITRE III REALISATION D'UNE INTERFACE GRAFIQUE
26
Figure 13 : capteur de pression
III.3.5.capteur de niveau :
Le mot "niveau" a de nombreux sens dans la langue
française. En physique, le niveau correspond à la distance entre
la surface d'un liquide et le fond du réservoir le contenant.
Le contrôle de niveau est utilisé dans de
nombreux et divers domaines, afin de connaître l'état de
remplissage de récipients, c'est-à-dire le niveau qu'y atteint le
produit présent.
Figure 14 : capteur de niveau résistif III.3.6
Notre programme de l'interface graphique
Comme il est indiqué précédemment,
l'ajout d'un élément sur l'interface graphique
génère automatiquement le code associé à ce
dernier. Nous avons donc pour notre interface :
function varargout = exampl1(varargin) % EXAMPL1 MATLAB code for
exampl1.fig
% EXAMPL1, by itself, creates a new EXAMPL1 or raises the
existing
% singleton*.
%
CHAPITRE III REALISATION D'UNE INTERFACE
GRAFIQUE
27
% H = EXAMPL1 returns the handle to a new EXAMPL1 or the handle
to
% the existing singleton*.
%
% EXAMPL1('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in EXAMPL1.M with the given input
arguments.
%
% EXAMPL1('Property','Value',...) creates a new EXAMPL1 or raises
the
% existing singleton*. Starting from the left, property value
pairs are
% applied to the GUI before exampl1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to exampl1_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only
one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help exampl1 %
Last Modified by GUIDE v2.5 01-Apr-2015 22:20:15
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn',
@exampl1_OpeningFcn, ... 'gui_OutputFcn', @exampl1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before exampl1 is made visible.
function exampl1_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 exampl1 (see VARARGIN)
% Choose default command line output for exampl1 handles.output =
hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes exampl1 wait for user response (see UIRESUME) %
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command
line.
CHAPITRE III REALISATION D'UNE INTERFACE GRAFIQUE
28
function varargout = exampl1_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;
axes(handles.axes7);x=imread('logo.jpg');imshow(x);
axes(handles.axes8);y=imread('logo.jpg');imshow(y);
% --- Executes on button press in read_button.
function read_button_Callback(hObject, eventdata, handles)
% hObject handle to read_button (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
global a k;
x1=0;
x2=0;
x3=0;
for k=1:1:handles.xSamples
b=a.analogRead(0);
c=a.analogRead(1);
d=a.analogRead(2);
b=b*150/1024;
c=c*5/1024;
d=d*10/1024;
set(handles.edit2_recive,'String',b);
set(handles.edit3,'String',c);
set(handles.edit4,'String',d);
x1=[x1,b];
x2=[x2,c];
x3=[x3,d];
axes(handles.axes1);plot(x1,'LineWidth',2);grid on; axis([0
handles.xSamples
0 150]);
axes(handles.axes2);plot(x2,'LineWidth',2);grid on; axis([0
handles.xSamples
0 5]);
axes(handles.axes3);plot(x3,'LineWidth',2);grid on; axis([0
handles.xSamples
0 10]);
pause(0.01);
end
function edit_text_samples_Callback(hObject, eventdata,
handles)
% hObject handle to edit_text_samples (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of
edit_text_samples as text
% str2double(get(hObject,'String')) returns contents of
edit_text_samples as a double
CHAPITRE III REALISATION D'UNE INTERFACE
GRAFIQUE
29
handles.data1=get(hObject,'String');
handles.xSamples=str2double(handles.data1);
guidata(hObject,handles);
% --- Executes during object creation, after setting all
properties. function edit_text_samples_CreateFcn(hObject, eventdata,
handles)
% hObject handle to edit_text_samples (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all CreateFcns
called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_recive_Callback(hObject, eventdata, handles)
% hObject handle to edit2_recive (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2_recive
as text
% str2double(get(hObject,'String')) returns contents of
edit2_recive as a double
% --- Executes during object creation, after setting all
properties. function edit2_recive_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2_recive (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all CreateFcns
called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as
text
% str2double(get(hObject,'String')) returns contents of edit3 as
a double
% --- Executes during object creation, after setting all
properties. function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all CreateFcns
called
CHAPITRE III REALISATION D'UNE INTERFACE
GRAFIQUE
30
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as
text
% str2double(get(hObject,'String')) returns contents of edit4 as
a double
% --- Executes during object creation, after setting all
properties. function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all CreateFcns
called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as
text
% str2double(get(hObject,'String')) returns contents of edit5 as
a double
% --- Executes during object creation, after setting all
properties. function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all CreateFcns
called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
CHAPITRE III REALISATION D'UNE INTERFACE
GRAFIQUE
31
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA) %
delete(instrfind({'Port'},{'COM13'}))
global a;
comport=num2str(get(handles.edit5,'String'));
a=arduino(comport);
guidata(hObject, handles);
1- Bouton Connect :
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA) % delete(instrfind({'Port'},{'COM13'}))
global a;
comport=num2str(get(handles.edit5,'String'));
a=arduino(comport);
guidata(hObject, handles);
2- Bouton Lire
% --- Executes on button press in read_button.
function read_button_Callback(hObject, eventdata, handles)
% hObject handle to read_button (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)
global a k;
x1=0;
x2=0;
x3=0;
for k=1:1:handles.xSamples
b=a.analogRead(0);
c=a.analogRead(1);
d=a.analogRead(2);
b=b*150/1024;
c=c*5/1024;
d=d*10/1024;
set(handles.edit2_recive,'String',b);
set(handles.edit3,'String',c);
set(handles.edit4,'String',d);
x1=[x1,b];
x2=[x2,c];
x3=[x3,d];
axes(handles.axes1);plot(x1,'LineWidth',2);grid on;
axis([0handles.xSamples 0 150]);
axes(handles.axes2);plot(x2,'LineWidth',2);grid on; axis([0
handles.xSamples 0 5]);
axes(handles.axes3);plot(x3,'LineWidth',2);grid on; axis([0
handles.xSamples 0 10]);
pause(0.01);
CHAPITRE III REALISATION D'UNE INTERFACE GRAFIQUE
|