MATLAB Answers

0

How do I keep sending a signal towards my object?

Asked by Martijn Roks on 1 Jul 2019
Latest activity Edited by Divya Yerraguntla on 19 Jul 2019
Hello,
I need to send a constant PWM signal towards a fan, but the signal is to short to change its speed. The fan can online receive a PWM signal and I only want it to receive a PWMsignal.
I tried it also with a led and the code works perfect, but the led just blinks.
I'am using a Gui, so if the code keeps sending the signal constant it also needs to be possible to turn a led on or something. And if I send the pwm signal I also need the possibility to change it any time I want with a other button? So a delay or something is not possible!!
Does anyone know how I can keep sending a specific PWM signal towards my object and I still can use the other buttons?
The code I posted in this post is just the code from the buttons I use.
function Snelheid_edit_Callback(hObject, eventdata, handles)
% hObject handle to Snelheid_edit (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 Snelheid_edit as text
% str2double(get(hObject,'String')) returns contents of Snelheid_edit as a double
% --- Executes on button press in Start_button.
function Start_button_Callback(hObject, eventdata, handles)
% hObject handle to Start_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a= arduino();
Snelheid= get(handles.Snelheid_edit, 'String');
snelheidpwm = str2num(Snelheid);
writePWMDutyCycle(a,'D3',snelheidpwm);
clear a;
% --- Executes on button press in Snelheid25_pushbutton.
function Snelheid25_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Snelheid25_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a= arduino();
writePWMDutyCycle(a,'D3',0.15)
clear a;
% --- Executes on button press in Snelheid50_button.
function Snelheid50_button_Callback(hObject, eventdata, handles)
% hObject handle to Snelheid50_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a= arduino();
writePWMDutyCycle(a,'D3',0.29)
clear a;
% --- Executes on button press in Snelheid75_button.
function Snelheid75_button_Callback(hObject, eventdata, handles)
% hObject handle to Snelheid75_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a= arduino();
writePWMDutyCycle(a,'D3',44.1);
clear a;
% --- Executes on button press in Snelheid100_button.
function Snelheid100_button_Callback(hObject, eventdata, handles)
% hObject handle to Snelheid100_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA
a = arduino();
writePWMDutyCycle(a,'D3',1)
clear a;
% --- Executes on button press in ledaan_pushbutton.
function ledaan_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to ledaan_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future of MATLAB
% handles structure with handles and user datversiona (see GUIDATA)
a= arduino();
if 1
LED = 'D3';
writeDigitalPin(a,'D3',1);
end
clear a;
% --- Executes on button press in leduit_pushbutton.
function leduit_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to leduit_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=arduino();
if 1
LED= 'D3';
writeDigitalPin(a,LED,0);
end
clear a;

  0 Comments

Sign in to comment.

1 Answer

Answer by Divya Yerraguntla on 18 Jul 2019
Edited by Divya Yerraguntla on 19 Jul 2019

Hi,
I understand that you want to select a PWM signal of a particular duty cycle and send the selected signal to the Arduino Board continuously.
To achieve this, try using a Toggle Button Group and not a Push Button. A Push Button will send the PWM signal to the Arduino only when the button is clicked and not continuously and probably that is the reason why the LED is blinking and not glowing continuously. A Toggle Button Group in App Designer could be used to toggle between different PWM signals. It sends the selected signal to the board continuously until another signal in the group is selected. Find the below links for more details on the Toggle Button Group.
Toggle Button Group UI:
Toggle Button Group Properties:
Hope it helps!

  0 Comments

Sign in to comment.