set a timer in the operant script - Printable Version

+- Forums (
+-- Forum: Bpod (
+--- Forum: Software (
+--- Thread: set a timer in the operant script (/showthread.php?tid=3441)

set a timer in the operant script - Samira - 08-31-2022

Hello everyone!
I am a new Bpod user and would like to set a timer to end a session.
Specifically, I am using the Bpod system in order to perform a sucrose preference test, so I need to know the number of licks of two Bpod systems. To do this I use the operant script but I would like to add a 30 minute timer for example. For now, I stopped the script manually...
Thank you in advance for your help,

RE: set a timer in the operant script - George - 09-01-2022

Hello, you can use the tic and toc functions to measure time in Matlab like this:

tic % Store current time for reference with toc

for currentTrial = 1:nTrials
    % do your trial and log data

    if toc > 30 * 60 % toc will return time since tic in seconds


RE: set a timer in the operant script - Josh - 09-01-2022

Hello Samira,

Another way is:

timeSinceSessionStart = now*100000 - BpodSystem.ProtocolStartTime;

This will return the time in seconds since the protocol started. Note that this time is measured by MATLAB, not the state machine clock. The two clocks will drift slightly, but if the point is to automate session-end, it should work.

This way of doing it will allow you to use tic/toc inside your code for debugging if necessary.