How do I display the PWM servo signal using the GUI axis?

5 views (last 30 days)
apri zulham
apri zulham on 14 May 2020
Edited: apri zulham on 18 May 2020
HI,
Was wondering if you could help, I have a school assignment to make a project, and I have some problems
How do I display the PWM servo signal using the GUI axis?
I use the slider to control the servo, I can't use 'readDigitalPin' to read the pins used by the servo, what should I do?
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
global s1;
slider=get(hObject,'value');
set(handles.edit1,'string',num2str(slider));
guidata(hObject,handles);
pos1=slider/180;
writePosition(s1,pos1);
function edit1_Callback(hObject, eventdata, handles)

Answers (1)

apri zulham
apri zulham on 18 May 2020
Edited: apri zulham on 18 May 2020
I have tried to make a simple coding, but I have a problem when I set slider1, why do axes2 react too?
function slider1_Callback(hObject, eventdata, handles)
global s1;
slider=get(hObject,'value');
set(handles.edit1,'string',num2str(slider));
guidata(hObject,handles);
pos1=slider/180;
writePosition(s1,pos1);
y1= [0 1 0 0 ];
x1= [0 0 1 20 ];
y2= [0 1 0 0 ];
x2= [0 0 1.5 20 ];
y3= [0 1 0 0 ];
x3= [0 0 2 20 ];
i=0;
i=i+1;
v(i)=readPosition(s1);
if (v(i)<0.5)
stairs(x1,y1,'LineWidth',2);
elseif (v(i)==0.5 || v(i)>0.5 && v(i)~=1)
stairs(x2,y2,'LineWidth',2);
elseif (v(i)==1)
stairs(x3,y3,'LineWidth',2);
end
axes(handles.axes1);
set(gca,'XTick', 0:1:20);
xlabel('lebar pulsa (ms)');
function slider2_Callback(hObject, eventdata, handles)
global s2;
slider=get(hObject,'value');
set(handles.edit2,'string',num2str(slider));
guidata(hObject,handles);
pos1=slider/180;
writePosition(s2,pos1);
y1= [0 1 0 0 ];
x1= [0 0 1 20 ];
y2= [0 1 0 0 ];
x2= [0 0 1.5 20 ];
y3= [0 1 0 0 ];
x3= [0 0 2 20 ];
i=0;
i=i+1;
v(i)=readPosition(s2);
if (v(i)<0.5)
stairs(x1,y1,'LineWidth',2);
elseif (v(i)==0.5 || v(i)>0.5 && v(i)~=1)
stairs(x2,y2,'LineWidth',2);
elseif (v(i)==1)
stairs(x3,y3,'LineWidth',2);
end
axes(handles.axes2);
set(gca,'XTick', 0:1:20);
drawnow;

Community Treasure Hunt

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

Start Hunting!