global com;
arduino = serial(com,'BaudRate',9600);
try
fopen(arduino);
catch
instrreset;
fopen(arduino);
end
baca=fscanf(arduino, '%s');%1x7 14 char
fclose(arduino);
cell = strsplit(baca,'#');
sensor=cell2mat(cell(1,1));
val=cell2mat(cell(1,2));
set(handles.txt12,'String',sensor);
clear all
clc
serialPort=serial('COM4','BaudRate',9600);
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(serialPort);
volt=[10,10,10,101,10,10,10,10];
%Voltages are mapped from 0-10 to 0-100000
for i=1:length(volt)
voltmapped(i)=map2(volt(i),0,10,0,100000);
end
display('Press any button to continue.');
pause
for i=1:length(voltmapped)
fprintf(serialPort,'%d',voltmapped(i));
end
fclose(serialPort);
Tidak ada komentar:
Posting Komentar