I want to use arduino in [appdesigner].

2 ビュー (過去 30 日間)
文宏
文宏 2022 年 10 月 16 日
コメント済み: 文宏 2022 年 10 月 16 日
Hello!
I want to use arduino in appdesigner, but I get an error. (as shown in the attached picture)
Error message[Too many input arguments]
Does anyone know how to solve this problem?
This source code communicates with arduino when [runbutton] is pressed as shown in the attached picture.(but,error)
classdef arduino < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
repeat matlab.ui.control.Spinner
Label_3 matlab.ui.control.Label
stopbutton matlab.ui.control.Button
run matlab.ui.control.Button
goal matlab.ui.control.Spinner
Label_2 matlab.ui.control.Label
default matlab.ui.control.Spinner
Label matlab.ui.control.Label
end
properties (Access = private)
Property % Description
a;%aruduino情報
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: run
function runButtonPushed(app, event)
app.a= arduino('com4', 'Uno', 'Libraries', 'Servo');
s = servo(app.a, 'D6');
for j=1:1:(app.repeat.Value)
for i=(app.default.Value):-2:(app.goal.Value)
val=i/180;
writePosition(s, val);
fprintf('Current motor position is %d degrees\n', i);
% pause(0.01)
end
for i=(app.goal.Value)-1:1:(app.default.Value)
val=i/180;
writePosition(s, val);
fprintf('Current motor position is %d degrees\n', i);
% pause(0.005)
end
end
end
% Button pushed function: stopbutton
function stopbuttonButtonPushed(app, event)
stop(app.a);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create Label
app.Label = uilabel(app.UIFigure);
app.Label.HorizontalAlignment = 'right';
app.Label.Position = [125 381 53 22];
app.Label.Text = {'初期角度'; ''};
% Create default
app.default = uispinner(app.UIFigure);
app.default.Position = [193 369 52 45];
app.default.Value = 40;
% Create Label_2
app.Label_2 = uilabel(app.UIFigure);
app.Label_2.HorizontalAlignment = 'right';
app.Label_2.Position = [125 298 53 22];
app.Label_2.Text = {'目標角度'; ''};
% Create goal
app.goal = uispinner(app.UIFigure);
app.goal.Position = [193 289 59 39];
app.goal.Value = 10;
% Create run
app.run = uibutton(app.UIFigure, 'push');
app.run.ButtonPushedFcn = createCallbackFcn(app, @runButtonPushed, true);
app.run.Position = [49 186 111 41];
app.run.Text = '実行';
% Create stopbutton
app.stopbutton = uibutton(app.UIFigure, 'push');
app.stopbutton.ButtonPushedFcn = createCallbackFcn(app, @stopbuttonButtonPushed, true);
app.stopbutton.Position = [223 186 119 41];
app.stopbutton.Text = {'停止'; ''};
% Create Label_3
app.Label_3 = uilabel(app.UIFigure);
app.Label_3.HorizontalAlignment = 'right';
app.Label_3.Position = [375 289 53 22];
app.Label_3.Text = {'繰り返し'; ''};
% Create repeat
app.repeat = uispinner(app.UIFigure);
app.repeat.Position = [443 289 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = arduino
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
*The source code below runs fine!
Of course, [MATLAB Support Palage for Arduino Hardware (ver 21.2.3)] is installed.
clear a s
a = arduino('com4', 'Uno', 'Libraries', 'Servo');
s = servo(a, 'D6');
angle=40;
first=angle/180; %0-1の値
for j=1:20
writePosition(s, first);
pause(1)
for i=40:-1:7
val=i/180;
writePosition(s, val);
fprintf('Current motor position is %d degrees\n', i);
end
for i=8:3:40
val=i/180;
writePosition(s, val);
fprintf('Current motor position is %d degrees\n', i);
end
end

採用された回答

Walter Roberson
Walter Roberson 2022 年 10 月 16 日
function app = arduino
You are defining a method named arduino for your class, which is interfering with calling the arduino library function
  6 件のコメント
Walter Roberson
Walter Roberson 2022 年 10 月 16 日
what error do you get after you rename to sample?
文宏
文宏 2022 年 10 月 16 日
Thank you!
I changed my pc and ran it and it worked!
I think perhaps it was still in the PC cache and the changes weren't taking effect!!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by