Showing posts with label Accessing Hardware using Matlab. Show all posts
Showing posts with label Accessing Hardware using Matlab. Show all posts

Friday, 1 February 2013

Access Webcam using Matlab

webcam.m

clc;
vid = videoinput('winvideo', 1, 'RGB24_320x240');
preview(vid);


Sunday, 27 January 2013

Access serial port using Matlab code


AccessSerialPort.m


clear all;
close all;

s = serial('COM1');  %assigns the object s to serial port

set(s, 'InputBufferSize', 256);  %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));

disp(['Port Setup Done!!',num2str(prop)]);

fopen(s);           %opens the serial port
t=1;
disp('Running');
x=0;
while(t<200 p="">   a =fread(s);
   a=max(a);
   x =[x a];
   plot(x);
   axis auto;
   grid on;
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;
   drawnow;
end

fclose(s); %close the serial port

Saturday, 26 January 2013

Controlling Keyboard switches with Matlab code


import java.awt.Robot;
import java.awt.event.*;

robot = Robot();

robot.keyPress(KeyEvent.VK_CAPS_LOCK);
robot.keyRelease(KeyEvent.VK_CAPS_LOCK);

I have shown with an example of "CAPS LOCK",but it can be replaced with the other buttons also


Thursday, 24 January 2013

Moving Mouse Pointer using Matlab code


clc;
import java.awt.Robot;
cursor = Robot;

cursor.mouseMove(0, 0);
screensize = get(0, 'screensize');
aspect_ratio = screensize(3)/screensize(4);
for i = 1:screensize(4)
cursor.mouseMove(aspect_ratio*i, i);
pause(0.005);
end

Controlling Mouse event using Matlab code


import java.awt.Robot;
import java.awt.event.*;

cursor = Robot;

cursor.mousePress(InputEvent.BUTTON3_MASK);
cursor.mouseRelease(InputEvent.BUTTON3_MASK);

%%%%%%%%%%%%%   Note %%%%%%%%%%%

BUTTON1 for left click
BUTTON2 for both
BUTTON3 for right click