control dc motor speed
4 次查看(过去 30 天)
显示 更早的评论
I have following code to control DC motor through H-Bridge and Arduino :
function motor_control2_OpeningFcn(hObject, eventdata, handles, varargin)
a = arduino('com3');
handles.a = a;
% 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 motor_control2 (see VARARGIN)
% Choose default command line output for motor_control2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes motor_control2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = motor_control2_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.a;
% --- Executes on button press in forwardpushbutton1.
function forwardpushbutton1_Callback(hObject, eventdata, handles)
handles.a.pinMode(9,'output');
handles.a.pinMode(10,'output');
handles.a.pinMode(3, OUTPUT);
handles.a.digitalWrite(9,0)
handles.a.digitalWrite(10,0)
handles.a.analogWrite(3,200) % control the speed 0- 255
Pin 3 is the enablepin which i can control the speed of motor.Now,i have a question, can i just adjust the speed using slider in GUI? How can i do that?I have the analog write value from 0 - 255 to adjust the speed, then i wish to adjust the speed when my motor move using slider. Any expert can help me?thanks
1 个评论
Nazrin Zaini
2014-10-22
i want to ask the same question,so did you got the solution?if you dont mind can you share the solution.
回答(1 个)
社区
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!