HydroCar_VoltAcq.m - MAE221/Thermodynamics-Lab GitHub Wiki

clear all
close all
clc
% Enter your Photon name%
name = '';

% Enter the unique access token for your Photon%
atoken = '';

% Enter the serial port for your Photon. If you have trouble finding the port or connecting to the serial, leave this blank.
port = '';

% Enter the input ports for your device.
voltPin = 'A0';

% Enter true if you are using a serial connection and false if you are using a cloud connection. If you having issues, just put false.
isUsingSerial = true;

%%

g = Photon(name, atoken, port);

if isUsingSerial
    g.disconnect;
end

% helpful var set
for i = 0:7
    msg = sprintf("D%0.0f = 'D%0.0f';", i,i);
    eval(msg);
end
for i = 0:7
    msg = sprintf("A%0.0f = 'A%0.0f';", i,i);
    eval(msg);
end

%% Collect data from the Photon
dT=60; %Time in between data acquisiton (in seconds)
% loop through each Volume measurement
fprintf('Voltage data will be acquired at every dT\n');
%fprintf('Be prepared to take current data when a voltage data point is displayed\n');
fprintf('Voltage data will be saved to a .mat file named at the end of the script\n');
fprintf('Make sure you are not overwriting a previous .mat file\n');
fprintf('Once ready to start taking data, hit Enter\n');
pause();
DlgH = figure;
i=1;
H = uicontrol('Style', 'PushButton', ...
                    'String', 'Break', ...
                    'Callback', 'delete(gcbf)');
%When complete with your measurements, hit the break button that pops up
%and the code will exit after the next data acquisition
while (ishandle(H))
   voltageIn(i,1)=g.analogRead(voltPin);
   voltageIn(i,1)
   pause(dT);
   i=i+1;
end
save('voltDat.mat','voltageIn');
clear g