Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Opening serial port
- s = serial('COM9');
- set(s,'BaudRate',9600,'Terminator','CR'); %Note that CR will be concatenated to all commands
- fopen(s);
- s %print for debugging
- t=1 %loop index
- while true
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %Here is code to mess with a joystick that works fine, using VS command
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if button(joy, 3) == 1 %Button3 of joystick should trigger position reading
- fprintf(s,'vs,0,0'); %Halt joystick movement
- pause(1) %Debouncing
- fprintf(s,'p'); %Axe-pos reading command
- fgets(s) %Reading the answer
- end
- %This way to increment follows the skipped parts and is required for timing
- if mod(t, 100)==0
- fprintf(s,'%s',Command);
- t=1;
- else
- t=t+1;
- end
- >> s = openserial()
- %properties as before, skipped to save space
- >> fprintf(s,'ps');
- >> fgets(s)
- ans =
- 100000,100000
- >> fprintf(s,'p');
- >> fgets(s)
- ans =
- 100000,100000,0
- >> fprintf(s,'p');
- >> fgets(s)
- ans =
- R
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement