any way to get the state of a lever?

MEDState Notation Repository Forums Coding Help Archive any way to get the state of a lever?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13076
    Med_Support
    Moderator
    mikediamond45

    Hello,
    I am using MedPC & I would like to know if there is any way to get the current state of a lever?
    That is, I would like to know how long a mouse depresses a lever?

    For example, I will only give reward if the mouse presses the lever for >= 5 seconds.
    ^Lever = 1
    ^Reward = 2

    S.S.1,
    S1,
    0.01": SET M = 0 ---> S2
    S2,
    #R^Lever: ADD M; SHOW 1, Counter, M;
    If (M >= 5) AND (output state of ^Lever = pressed) [@True, @False]
    @True: ON ^Reward ---> S3
    @False: ---> SX
    S3,
    1": OFF ^Reward; SET M = 0 ---> S2
    

    Is there any code that I can substitute for (output state of ^Lever = pressed) ?

    #13077
    Med_Support
    Moderator
    Gary Bamberger

    The following code sample should help:

    \***************************************************
    \ BEAM BREAK DEFINED - 20ms BREAK, 20ms RELEASE
    \***************************************************
    S.S.2, \ Beam Break Defined - 20ms Break, 20ms Release.
    S1, \ Inputs in Level Mode generate an input "count" on each
    \ interrupt. With a 10 ms system resolution 2 counts
    \ will be reached in 20 ms. The Z3 pulse is used to
    \ signal a completed Beam Break. The second statement resets
    \ the counter every 20 ms so that a partial Beam Break of
    \ less than 20 ms will not constitute a Response.
    #R1: ADD Y; IF Y >= 2 [@BeamBreak, @NoBeamBreak]
    @Break: Z3; SET Y = 0 ---> S2
    @NoBreak: ---> SX
    0.02": SET Y = 0 ---> S1
    
    S2, \ As long as the Beam is broken the second statement
    \ causes a re-entry to this State. This resets the
    \ the internal 20 ms timer so it never times out. When
    \ the Beam is released for 20 ms the timer times out
    \ and a Z4 pulse signals the release.
    0.02": Z4 ---> S1
    #R1: ---> S2
    

    The code was for input beams, but it will also work for levers in level mode. All you need to do is time the length between each Z-pulse. If it is greater than 5s, issue the reward.
    Gary

    #13081
    Med_Support
    Moderator
    mikediamond45

    yep, changing it to level mode & modifying the code worked, thx.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.