Borrar filtros
Borrar filtros

App Designer Switch Component

9 visualizaciones (últimos 30 días)
Allison McCrady
Allison McCrady el 26 de Mzo. de 2019
Hi,
I am still working on the app that I was writing before. We added vibration motors to the circuit and want them to vibrate at a certain force level and if they are selected to be used. I cannot get them to vibrate with the forces. I have attached the code if anyone has an idea to help me get this to work. I thought I had it, but I may not understand switch components enough.
Thanks in advance!
properties (Access = private)
stop;
done=0;
timeLogs;
forceLogs;
timeSecs;
filename;
T;
h;
a;
starttime;
t;
force;
grade;
force1;
force2;
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, a)
app.a=arduino('Com7','uno');
end
% Button pushed function: RUNButton
function RUNButtonPushed(app, event)
app.done=0;
app.stop=false;
app.starttime=datetime('now');
figure
ax=axes;
app.h=animatedline(ax);
ax.YGrid='on';
ax.YLim=[0 80];
ax.YLabel.String='Force (N)';
ax.XLabel.String='Time (hh:mm:ss)';
while ~app.stop
% Read current voltage value
voltage1 = readVoltage(app.a,'A2');
voltage2 = readVoltage(app.a,'A1');
% Calculate force from voltage (based on data sheet)
% Flipped for ease of use
app.force1=-(13.499*voltage1)+68.534; %from calibration with standard weights
app.force2=-(9.9586*voltage2)+49.882; %from calibration with standard weights
app.force=app.force1+app.force2;
% Get current time
app.t = datetime('now') - app.starttime;
% Add points to animation
addpoints(app.h,datenum(app.t),app.force)
% Update axes
ax.XLim = datenum([app.t-seconds(15) app.t]);
datetick('x','keeplimits')
drawnow
% Check stop condition
app.stop = app.done;
end
end
% Button pushed function: STOPButton
function STOPButtonPushed(app, event)
app.done=1;
[app.timeLogs,app.forceLogs] = getpoints(app.h);
app.timeSecs = (app.timeLogs-app.timeLogs(1))*24*3600;
app.T = table(app.timeSecs',app.forceLogs','VariableNames',{'Time_sec','Force_N'});
% Write table to file
writetable(app.T,app.filename)
[app.timeLogs,app.forceLogs] = getpoints(app.h);
app.timeSecs = (app.timeLogs-app.timeLogs(1))*24*3600;
plot(app.UIAxes,app.timeSecs,app.forceLogs)
end
% Value changed function: SaveAsEditField
function SaveAsEditFieldValueChanged(app, event)
value = app.SaveAsEditField.Value;
app.filename=value;
end
% Value changed function: GradeDropDown
function GradeDropDownValueChanged(app, event)
gradevalue = app.GradeDropDown.Value;
if gradevalue == '1'
app.grade = 1;
elseif gradevalue == '2'
app.grade = 2;
elseif gradevalue == '3'
app.grade = 3;
elseif gradevalue == '4'
app.grade = 4;
elseif gradevalue == '5'
app.grade = 5;
else
app.grade = 0;
end
end
% Value changed function: VibrationSwitch
function VibrationSwitchValueChanged(app, event)
value = app.VibrationSwitch.Value;
switch value
case 'On'
while ~ app.stop
if app.grade==1
while app.force1 >= 15
writeDigitalPin(app.a,'D6',1);
end
else
writeDigitalPin(app.a,'D6',0);
end
if app.grade==2
while app.force1 >= 25
writeDigitalPin(app.a,'D6',1);
end
else
writeDigitalPin(app.a,'D6',0);
end
if app.grade==3
while app.force1 >= 35
writeDigitalPin(app.a,'D6',1);
end
else
writeDigitalPin(app.a,'D6',0);
end
if app.grade==4
while app.force1 >= 45
writeDigitalPin(app.a,'D6',1);
end
else
writeDigitalPin(app.a,'D6',0);
end
if app.grade==5
while app.force1 >= 55
writeDigitalPin(app.a,'D6',1);
end
else
writeDigitalPin(app.a,'D6',0);
end
% Check stop condition
app.stop = app.done;
end
case 'Off'
writeDigitalPin(app.a,'D6',0);
end

Respuestas (0)

Categorías

Más información sobre Signal Integrity Kits for Industry Standards en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by