%SETUP the Serial Port for Communication

% %=====clean up any leftover serial connections==============
clear all
clc
try
    fclose(instrfind) %close any bogus serial connections
end
% 
% %Set COMs and baudrate
COM = 'COM5';
baudrate = 9600; 
stopbits = 1;
databits = 8;

s = serial(COM, 'DataBits', databits, 'BaudRate', baudrate, 'Parity', 'None', 'StopBits', stopbits);
set(s,'Timeout',10);
s.FlowControl = 'none';
fopen(s);

u_input = '';
t_data = '';

pause(1)
while(1)
    fprintf(s , '8');
    pause(0.1);
    t_data = fscanf(s, '%s');
    pause(0.1);
    if(strcmp(t_data,'irq') == 1)
        u_input = input('Give input:\n');
        pause(0.1);
        fprintf(s, '4');
    else
        fprintf('%s\r', t_data);
    end
    pause(1);
end