tinker.m - MAE221/Thermodynamics-Lab GitHub Wiki

%{
    This is a matlab version of the tinker file provided by
    the particle company
%}

%Enter your photon name%

name = 'PHOTON_NAME';
%Enter the unique access token for your photon%

atoken = 'ACCESS_TOKEN';

% Enter the serial port your Photon is connected to. Leave blank if you have issue finding your port connecting to serial.
port = 'SERIAL_PORT';

%%
% 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

g = Photon(name, atoken, port);

while true
    line = input('Comm>> ', 's');
    if contains(line, 'exit')
        break;
    end
    
    try
        msg = '';
        if ~contains(line, 'breadth')
            msg = strcat('g.', line);
        else
            par = strfind(line, ')');
            msg = strcat(line(1:par-1), ',g)');
            disp(msg);
        end
        eval(msg);
    catch ME
        if strcmp(ME.identifier, 'MATLAB:UndefinedFunction')
            disp('Invalid commandd.');
        else
            disp(ME.identifier);
            disp(ME);
        end
    end
end

clear g; 

% causes the pin to breath once
function breadth(pin, g)
    f = 0:0.1:3;
    for i=f
        g.analogWrite(pin, i)
    end
    for i=flip(f)
        g.analogWrite(pin, i)
    end
end