clc % Clear the MATLAB command window clear % Clear the MATLAB variables % Make the LJM .NET assembly visible in MATLAB ljmAsm = NET.addAssembly('LabJack.LJM'); handle = 0; True = 0; uint8 data; uint8 count; count = 6; double dRH; double dTemp; delay250ms = 250/1000; %250 milisec delay20ms = 20/1000; %20milisec delay40ms = 40/1000; %20milisec delay1micsec = 1/1000000; %1microsec pin = 'FIO1'; stateInput = 0; MAXTIMINGS = 85; try % Open first found LabJack % Any device, Any connection, Any identifier [ljmError, handle] = LabJack.LJM.OpenS('ANY', 'ANY', 'ANY', handle); for k=1:1:5 lastState = 1; uint8 j; uint8 i; j=0; data = zeros(1,5,'uint8'); LabJack.LJM.eWriteName(handle, pin, 1); pause(delay250ms); LabJack.LJM.eWriteName(handle, pin, 0); pause(delay20ms); LabJack.LJM.eWriteName(handle, pin, 1); pause(delay40ms); b=0; for i=0:1:MAXTIMINGS counter = 0; [ljmerror, stateInput]=LabJack.LJM.eReadName(handle, pin, 0); while stateInput == lastState [ljmerror, stateInput]=LabJack.LJM.eReadName(handle, pin, 0); counter=counter+1; pause(delay1micsec); if (counter == 255) break; end end %---Arduino scripts count 5, Matlab Script count 255, as if %eReadname notworking at all [ljmerror, lastState]=LabJack.LJM.eReadName(handle, pin, 0); if counter == 255 break; end if (i >= 4) && (mod(i,2) == 0) data = bitshift(data,1); if counter > count bitor(data,1); j=j+1; end end end counterDisp = counter dataDisp = data %b = dec2bin(a) pause(2); end catch e showErrorMessage(e) LabJack.LJM.CloseAll(); return end % try % % Close handle % LabJack.LJM.Close(handle); % catch % showErrorMessage(e) % end