function timelapse_timer(vid,~)
% This callback function triggers the acquisition and saves frames to an AVI file.

% Copyright 2011 The MathWorks, Inc.

% trigger the acquisition and get the frame
trigger(vid);
frame = getdata(vid,1);

% Retrieve the total number of frames acquired
numframes_acquired = get(vid,'FramesAcquired');

% Drop every other frame:  If the frame is odd,
% keep it.  If it is an even frame, do not keep it.
keepframe = (mod(numframes_acquired,2) == 1);

% Insert your processing code here

if(~keepframe)
    return;
end

% Retrieve the VideoWriter object stored in the UserData
% property.
vwObj = get(vid,'UserData');

% Add the frame to the AVI
writeVideo(vwObj, frame);

end
