Bonjour,

J'ai développé une interface graphique avec (pour simplifier) un bouton START qui lit un voltage sous Arduino.
Mais j'aimerai que ce bouton START soit aussi activé lorsqu'on appuie sur un bouton physique de mon Arduino --> le pin Digital passe de 0 à 1 à l'appuie et donc doit lancer le START.

J'arrive à faire soit l'un soit l'autre mais je n'ai pas réussi à coder un code qui permet d'offrir le choix entre soit j'appuie sur le GUI soit j'appuie sur le bouton physique.
Il faut que j'utilise le Event ?

Merci beaucoup ^^


Ici un bout de code simplifié :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function GUI_start()
 
% init figure control
close all
clc
hObj=figure(); % my big parent handle
uicontrol(gcf,'Style', 'push', 'String', 'PLAY','FontSize',24,'units','normalized','Position',[0.1 0.1 0.5 0.2],'tag','PressStart','CallBack', @code_readArduinoAnalog);
Volt=uicontrol(gcf,'Style', 'edit', 'String', '0','FontSize',10,'units','normalized','Position',[0.1 0.5 .5 .2]);
setappdata(hObj,'Volt',Volt);
 
% init arduino
a=arduino('COM7','due');
setappdata(hObj,'a',a);
 
function code_readArduinoAnalog(hObjButtonStart,~,~) %(source,event,handleGlobal)
 
a=getappdata(hObjButtonStart.Parent,'a');
data=readVoltage(a,'A1');
set(getappdata(hObjButtonStart.Parent,'Volt'),'String',num2str(data));
 
%% where to put and how to call it ??? 
function code_readArduinoDigital(hObjButtonPhysical,~,~)
 
a=getappdata(hObjButtonPhysical.Parent,'a');
while 1==1 % infite loop to read in continuous the digital pin
    if readDigitalPin(a,'D13')==0 
        % the physical button links in pin13 allows to lauch the measure as the pushbutton in GUI
        hStart=findobj('tag','pressStart'); 
        feval(get(hStart,'Callback'),hStart,[]);
    end
end