Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Delete Opened Ports in MATLAB
- clear all;
- clc;
- delete(instrfind)
- ser = serial('COM9', 'BaudRate',115200, 'Timeout',10);
- syms right;
- syms left;
- syms stan;
- stan = 1;
- syms i;
- syms iPuls;
- volume = 0;
- fopen(ser);
- i=0;
- tim = 0;
- actval=0;
- tim2 = 0;
- while true
- d = fscanf(ser, '%d %d %d');
- value1 = d(1,:);
- value2 = d(2,:);
- value3 = d(3,:);
- fprintf("%d\t%d\t%d\t%d\t%d\t%d\r\n", value1,value3,stan,volume,i,tim);
- %stan 1
- %%%%%oczekiwanie na ruch
- if(value1<600 && value3>600 && stan == 1)
- stan = 2;
- tim = i;
- tim2 = i;
- elseif(value1>600 && value3<600 && stan == 1)
- stan = 3;
- tim=i;
- tim2 = i;
- end
- %stan 2
- if((value1<400 || value3<400) && stan == 2 && (i-tim)>30)
- stan = 6;
- elseif(value1>600 && value3<600 && (i-tim2) < 20 && stan == 2)
- stan = 4;
- elseif(value1>600 && (i-tim2) > 20 && stan == 2)
- stan = 1;
- end
- %stan 3
- if((value1<600 || value3<600) && stan == 3 && (i-tim)>30)
- stan = 6;
- elseif(value1<600 && value3>600 && (i-tim2) < 20 && stan == 3)
- stan = 5;
- elseif(value3>600 && (i-tim2) > 20 && stan == 3)
- stan = 1;
- end
- %stan 4
- %%%%przewiniecie w prawo
- if(stan==4)
- system('nircmd.exe sendkey 176 press');
- if(value1>600 && value3>600 && stan == 4)
- stan = 1;
- end
- end
- %stan 5
- if(stan == 5)
- %%%przewinięcie w lewo
- system('nircmd.exe sendkey 177 press');
- end
- if(value1>600 && value3>600 && stan == 5)
- stan = 1;
- end
- if(stan == 6)
- volume = (value2 / 4) * 1000;
- volume = floor(volume);
- if(value2>600 || (actval-value2)>1000)
- stan = 1;
- else
- system(sprintf('nircmd.exe setsysvolume %d',volume));
- end
- actval=value2;
- end
- pause(10/1000);
- i = i+1;
- plot(d, 'LineWidth',2,'Color',[0,0,1.0])
- ylim([0,4000])
- drawnow
- end
- fclose(ser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement